C:错误:无效使用qualified-name

C:错误:无效使用qualified-name,第1张

概述更新:我认为这是固定的.多谢你们! 我收到了一个错误,我无法弄明白. 我有这个代码: //A Structure with one variable and a constructorstruct Structure{ public: int dataMember; Structure(int param);};//Implemented constructorSt 更新:我认为这是固定的.多谢你们!

我收到了一个错误,我无法弄明白.
我有这个代码:

//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所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1219854.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-05
下一篇2022-06-05

发表评论

登录后才能评论

评论列表(0条)

    保存