【发布时间】:2013-10-09 13:00:55
【问题描述】:
我已经编写了一个实验库,并且正在研究 Array 我有 error: unknown class name 'Exception'; did you mean 'std::exception'。我该如何解决?
数组.hpp
#ifndef _RFwC__ARRAY_HPP_
#define _RFwC__ARRAY_HPP_
#include "util.hpp"
#include "Object.hpp"
#include "IDefaultType.hpp"
#include "Exception.hpp"
class ArrayException : public Exception {}; // here error
class IndexOutOfRangeException : public ArrayException {};
template<typename T_Value>
class Array : public Object, IDefaultType{
public:
Array(const intnum_t _length);
Array();
// next array code and closing for guard symbols
异常.hpp
#ifndef _RFwC__EXCEPTION_HPP_
#define _RFwC__EXCEPTION_HPP_
#include "IThrowable.hpp"
#include "Object.hpp"
#include "String.hpp"
class Exception : public Object, IThrowable {
public:
Exception(const String _message, const Exception * _pInner);
Exception(const String _message);
Exception();
const String getMsg() const;
const Exception * getInner() const;
virtual void onThrow();
protected:
String __msg;
const Exception * __pInner;
};
#endif // _RFwC__EXCEPTION_HPP_
输出:
c++ -DPLATFORM_=linux -DCAPACITY_=32 -std=c++11 -fPIC -o obj/core_Exception.cpp.o -c src_Core/Exception.cpp
In file included from src_Core/Exception.cpp:23:
In file included from src_Core/Exception.hpp:26:
In file included from src_Core/IThrowable.hpp:27:
In file included from src_Core/String.hpp:28:
src_Core/Array.hpp:31:31: error: unknown class name 'Exception'; did you mean 'std::exception'?
class ArrayException : public Exception {};
^~~~~~~~~
std::exception
/usr/bin/../lib/gcc/i686-linux-gnu/4.7/../../../../include/c++/4.7/exception:61:9: note: 'std::exception' declared here
class exception
^
1 error generated.
make: *** [core_Exception.cpp.o] Ошибка 1
【问题讨论】:
-
这就是标题中的全部内容吗?难道是你从头文件中复制粘贴了一些东西,所以
Exception.hpp上面的头文件保护与另一个头文件上的头文件保护相同,有效地防止了Execption.hpp的内容被编译器读取? -
这是一个循环包含的情况。
-
@john,完全正确,我刚刚注意到了!
-
这可能不是问题,但是以下划线后跟大写字母 (
_RFwC__ARRAY_HPP_) 和包含两个连续下划线 (__msg) 的名称保留给实现.不要使用它们。