C++ 如何解决错误:“使用”前需要不合格的id?
这是我的班级,我犯了一个非常奇怪的错误C++ 如何解决错误:“使用”前需要不合格的id?,c++,C++,这是我的班级,我犯了一个非常奇怪的错误 #ifndef MYEXCEPTION_H #define MYEXCEPTION_H #include <string> #include <exception> //Error in next line using namespace std; class MyException : public exception { public: MyException(string& whatsup) : mess
#ifndef MYEXCEPTION_H
#define MYEXCEPTION_H
#include <string>
#include <exception>
//Error in next line
using namespace std;
class MyException : public exception {
public:
MyException(string& whatsup) : message(whatsup) { }
~MyException() throw() {}
const char* what(){return message.c_str();}
private:
string message;
};
#endif
不相关,但在头文件中使用namespace std会被轻视,而且这不是您的实际代码,它在中编译得很好:错误可能是由源文件中具有`include MyException.h的include文件生成的。顺便问一下,C语言头文件和C++头文件之间的区别是什么?
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/myrecordproject
mkdir -p build/Debug/GNU-MacOSX
rm -f build/Debug/GNU-MacOSX/main.o.d
g++ -c -g -I/usr/local/include/cppunit -I/usr/local/include/boost -MMD -MP -MF build/Debug/GNU-MacOSX/main.o.d -o build/Debug/GNU-MacOSX/main.o main.cpp
In file included from MyRecord.h:11,
from main.cpp:13:
MyException.h:14: error: expected unqualified-id before 'using'
make[2]: *** [build/Debug/GNU-MacOSX/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2