c++: error:无效使用限定名称
C++: error: invalid use of qualified-name
更新:我认为它是固定的。谢谢你们了!
我得到一个错误,我只是不知道它。我有这样的代码:
//A Structure with one variable and a constructor
struct Structure{
public:
int dataMember;
Structure(int param);
};
//Implemented constructor
Structure::Structure(int param){
dataMember = param;
}
//A class (which I don't plan to instantiate),
//that has a static object made from Structure inside of it
class unInstantiatedClass{
public:
static Structure structObject;
};
//main(), where I try to put the implementation of the Structure from my class,
//by calling its constructor
int main(){
//error on the line below
Structure unInstantiatedClass::structObject(5);
return 0;
}
在"Structure unInstantiatedClass::structObject(5);"这一行,我得到了如下错误:
error: invalid use of qualified-name 'unInstantiatedClass::structObject'
我在谷歌上搜索了这个错误,并浏览了几个论坛帖子,但每个人的问题似乎都不一样。我也试着用谷歌搜索"类内的静态结构对象"和其他相关短语,但没有发现任何我认为真正与我的问题相关的短语。
我在这里要做的是:有一个我从未实例化过的类。并且在该类中有一个静态对象,该对象有一个可以通过构造函数设置的变量。
任何帮助都是感激的。谢谢。
静态成员的定义不能在函数内部:
class unInstantiatedClass{
public:
static Structure structObject;
};
Structure unInstantiatedClass::structObject(5);
int main() {
// Do whatever the program should do
}
我认为问题是结构unInstantiatedClass: structObject (5);在主要范围内。把它放在外面。
您需要使用以下代码:
UPDATE:将静态成员的初始化移到全局作用域。
// In global scope, initialize the static member
Structure unInstantiatedClass::structObject(5);
int main(){
return 0;
}
相关文章:
- 在没有参数列表的情况下使用模板名称"Event"无效,模板问题
- 为什么右值不能绑定到非常量左值引用,除了写入临时无效的事实?
- 模板化的模板参数名称在方法头上无效
- 调用boost v1.58中的函数时出现模板名称使用无效错误
- HTTP 请求中的标头名称无效
- Clang 3.8 错误:参数 '-fuse-ld=gold-2.25' 中的链接器名称无效
- 在没有参数列表的情况下无效使用模板名称"节点"
- Android NDK Linker (GStreamer) - 无效的链接器名称 -fuse-ld=gold.
- 如何使用libpq库和C 绑定无效的语句
- C++中名称查找和名称绑定之间的区别
- 如何在没有参数列表的情况下定义向量无效使用模板名称 std::vector
- 错误:在没有参数列表的情况下无效使用模板名称“ExTree” ||如果解决这个问题怎么办?(初学者)
- C++代码编译失败,错误"长类型名称"无效
- 没有参数列表的模板名称使用无效
- C++ - 运行 Moses 解码器时区域设置名称无效异常
- 使用 VS2012 编译库时符号名称无效
- 抛出 'std::runtime_error' what() 的实例:区域设置::facet::_S_create_c_locale 名称无效
- C++:服务器上的 boost::文件系统问题(区域设置::facet::_S_create_c_locale 名称无效
- std::locale::facet::_S_create_c_locale 名称无效
- 了解区域设置类时,区域设置:facet::_S_create_c_locale名称无效