gpt4 book ai didi

c++ - 无法解析符号 'A'

转载 作者:太空狗 更新时间:2023-10-29 23:53:31 28 4
gpt4 key购买 nike

我有这个问题 Symbol 'A' could not be resolved in file B.h ,我正在为 C/C++ 开发人员使用 Eclipse IDE:

//B.h file

#ifndef __B_H__
#define __B_H__

#include "A.h"



class B: public cs::A{

};

#endif

包括A.h文件:

//A.h file

#ifndef A_H_
#define A_H_
namespace cs{
class A {


};
}

#endif

我在这里缺少什么?

最佳答案

您将类 A 放置在命名空间中,您应该在使用它时保持命名空间解析:

class B:  public cs::A{

};

或者

//B.h file

#ifndef __B_H__
#define __B_H__

#include "A.h"

using namespace cs;

class B: public A{

};

#endif

这是不推荐的(查看 Als 的评论)。

您还可以这样做,以避免每次使用 A(您应该在第一个解决方案中这样做)时都保留整个 namespace 限定,以及使用所有命名空间:

//B.h file

#ifndef __B_H__
#define __B_H__

#include "A.h"

using cs::A;

class B: public A{

};

#endif

关于c++ - 无法解析符号 'A',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10461031/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com