#include <iostream using namespace std; class Test() { ________第一个空行 Test(int i = 10) { x = i +x; } intGentnum() { return Test::x+7; } }; ________第二个空行 int main() { Test test; cout << test.Getnum() << endl; }
p113答案
#include <iostream> using namespace std; class Test { static int x;//第一个空 看到下面x重复出现 则推断适合的类型只有静态成员函数 Test() { } Test(int i = 10) { x = i + x; } int Getnum() { return Test::x + 7; } }; int Test::x = 83;//第二个空 只有在类外才可以声明初值 int main() { Test test; cout << test.Getnum() << endl; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。