我有两个文件,homework1.cc
和homework1.h
。
homework1.cc
的顶部为
#include <iostream>
#include <fstream>
#include <cstring>
#include <GL/glut.h>
#include "homework1.h"
using namespace std;
, homework1.h
的顶部为
#ifndef _rt_H
#define _rt_H
#include <cmath>
#include <vector>
#include <list>
#include <GL/glut.h>
using namespace std;
这是我在homework1.h
中使用list
的地方
class surTriangle
{
float x;
float y;
float z;
list <int> surTriangles;
bool compareVertex(Vector3f anotherVec)
{
if(anotherVec[0] == x && anotherVec[1] == y && anotherVec[2] == z)
return true;
return false;
}
}
当我尝试编译homework.cc
时,编译器报告
homework1。Cc:8:错误:' using '
之前预期的unqualified-id
然而,当我删除#include <list>
或上面的第三段代码时,它编译成功。
你能帮我找出问题是什么吗?
在类声明之后需要一个分号。(homework1.h
类片段的最后一行)。否则使用将被解释为
class X {
} x;
您在类定义的末尾忘记了;
。
在调试解析错误时,考虑预处理器是如何工作的是有用的;在你的脑海中(或者用gcc -E
,如果你想真正正确地看待它)想象一下#include
指令被解析后的代码是什么样子。
using
是"unexpected",这通常表示终止/结束前一个语句的问题。这会导致发现缺少分号,这是一个典型的打字错误。