hyp永恒冰川 2022-04-11 22:40 采纳率: 66.7%
浏览 18
已结题

我想问下我这个报错是什么原因啊?

这是全部代码:


```c++
#include<iostream>
#include<string>
using namespace std;
class son {
public:
    string name;
};
class father {
public:
    son son1;
    static string name;
    static int passwd;
    static void func() {
        name = "root";
        passwd = 123456;
        cout << "this is a static function" << endl;
    }
};
void function() {
    father::func();
}
void function2() {
    father f1;
    f1.func();
}
int main() {
    function();
    function2();
    return 0;
}

错误描述:

img

  • 写回答

1条回答 默认 最新

  • aabyte 2022-04-12 00:03
    关注

    第16行和第17行 静态成员变量不能在类体里初始化

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 4月14日
  • 创建了问题 4月11日