'ClassName'不命名类型
'ClassName' does not name a type
我见过类似的答案,但我似乎无法仅通过查看这些(例如这个或那个)来解决我的答案。
所以,我有那个.
啊
#ifndef INCLUDE_CLASS_NAME
#define INCLUDE_CLASS_NAME
#include <B.h>
using namespace C;
D::DPtr myvariable; <-- Error in here
#endif
在包括 B.h 我有这个:
namespace C{
namespace E{
class D
{
public:
typedef shared_ptr<D> DPtr;
}
} //end of namespace E
} // end of namespace C
为什么我在提到的行中收到此错误:
'D' does not name a type
我包括定义类的 .h 文件。我错过了什么?
符号D
在命名空间E
内,在命名空间C
内,所以完全限定名是C::E::D
。
因此,请执行以下任一操作:
-
添加
E::
以正确引用D
:mutable E::D::DPtr myvariable;
-
在
using
指令中也声明E
:using namespace C::E;
你错过了命名空间 E...
mutable E::D::DPtr myvariable; // should work
您正在尝试调用根据预处理器尚不存在的函数。在调用函数之前,您需要定义函数:
int mainFunction(){
int foo(int bar){ //define function FIRST...
return bar;
}
foo(42) //call it later.
}
这应该可以消除错误。这不会:
int mainFunction(){
foo(42) //trying to call a function before it's declared does not work.
int foo(int bar){
return bar;
}
}
相关文章:
- ArduinoJson 6.15.2:JsonObject没有命名类型
- 防止主数据类型C++的隐式转换
- 大量序列中核苷酸类型的快速计数
- 如何从C++中的依赖类型中获得它所依赖的类型
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如何获取std::result_of函数的返回类型
- 从父命名空间重载类型
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 访问者访问变体并返回不同类型时出错
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- C++ 两个类相互引用 错误:'ClassName'之前预期的类型说明符
- Arduino:'void (ClassName::)()' 类型的参数在附加中断时与'void (*)()'不匹配
- 如何解决字段'classname'类型错误不完整
- Visual Studio c++代码格式-返回类型+ classname::func缩进
- 错误:classname没有命名类型
- ClassName&作为返回类型是什么意思?
- 'ClassName'不命名类型