
我收到了一个错误,我无法弄明白.
我有这个代码:
//A Structure with one variable and a constructorstruct Structure{ public: int dataMember; Structure(int param);};//Implemented constructorStructure::Structure(int param){ dataMember = param;}//A class (which I don't plan to instantiate),//that has a static object made from Structure insIDe of itclass unInstantiatedClass{ public: static Structure structObject;};//main(),where I try to put the implementation of the Structure from my class,//by calling its constructorint main(){ //error on the line below Structure unInstantiatedClass::structObject(5); return 0;} 在“结构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} 总结 以上是内存溢出为你收集整理的C:错误:无效使用qualified-name全部内容,希望文章能够帮你解决C:错误:无效使用qualified-name所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)