c++ - 编译器报告 : error: expected unqualified-id before ‘using’

标签 c++

我有两个文件,homework1.cchomework1.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;

这是我使用 list 的地方在homework1.h

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: error: expected unqualified-id before ‘using’

但是,当我删除 #include <list> 时或上面的第三段代码编译成功。

你能帮我找出问题所在吗?

最佳答案

类声明后需要一个分号。 (homework1.h 类片段的最后一行)。否则 using 被解释为标识符,如

class X {
} x;

关于c++ - 编译器报告 : error: expected unqualified-id before ‘using’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8347504/

相关文章:

c++ - 将信号连接到具有恒定值的插槽

c++ - 在 linux 上安装自定义字体(相当于 windows AddFontResource)

c++ - 比较两个 vector<bool> 与 SSE

c++ - 将已存在的对象从 C++ 返回到 Lua

javascript - 将 C++ 后端连接到 Javascript

c++ - 初始化为NULL的指针数组的成员占用内存吗?

c++ - 并发可变优先级队列

c++ - 双线性插值,我的实现有问题

c++ - 为什么这个 OpenCV 代码什么都不做?

c++ - 分配给 *this 用于构造函数委托(delegate)