C:错误:无效使用qualified-name
发布时间:2020-12-16 10:23:53 所属栏目:百科 来源:网络整理
导读:更新:我认为这是固定的.多谢你们! 我收到了一个错误,我无法弄明白. 我有这个代码: //A Structure with one variable and a constructorstruct Structure{ public: int dataMember; Structure(int param);};//Implemented constructorStructure::Structure
更新:我认为这是固定的.多谢你们!
我收到了一个错误,我无法弄明白. //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; } 在“结构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 } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |