nab*_*bil 2 c++ eclipse oop header eclipse-cdt
我有这个问题符号'A'无法在文件Bh中解析,我正在使用Eclipse IDE for C/C++ Developers:
//B.h file
#ifndef __B_H__
#define __B_H__
#include "A.h"
class B: public cs::A{
};
#endif
Run Code Online (Sandbox Code Playgroud)
包括Ah文件:
//A.h file
#ifndef A_H_
#define A_H_
namespace cs{
class A {
};
}
#endif
Run Code Online (Sandbox Code Playgroud)
我在这里缺少什么?
您将该类A放在命名空间中,您应该在使用它时保持命名空间的解析:
class B: public cs::A{
};
Run Code Online (Sandbox Code Playgroud)
要么
//B.h file
#ifndef __B_H__
#define __B_H__
#include "A.h"
using namespace cs;
class B: public A{
};
#endif
Run Code Online (Sandbox Code Playgroud)
不建议使用(查看Als的评论).
此外,您可以这样做,以避免每次使用时保留整个命名空间限定A(您应该在第一个解决方案中执行),以及using所有命名空间:
//B.h file
#ifndef __B_H__
#define __B_H__
#include "A.h"
using cs::A;
class B: public A{
};
#endif
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1377 次 |
| 最近记录: |