注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
第三周的填空题作业,有一道题不会。。。
下面程序输出的结果是
4,6
请填空:
class A {
int val;
public:
A( int n) { val = n; }
int GetVal() { return val;}
};
class B: public A {
private:
int val;
public:
B(int n):______________{ }
int GetVal() { return val;}
};
int main() {
B b1(2);
cout<<b1.GetVal()<< ","
<< b1.A::GetVal()<< endl;
return 0;
}
我在下滑线上填上val(n),然后编译不通过。。。
C:\Users\L538\Desktop\Codeblocks\fdsfaee\main.cpp||In constructor 'B::B(int)':|
C:\Users\L538\Desktop\Codeblocks\fdsfaee\main.cpp|15|error: no matching function for call to 'A::A()'|
C:\Users\L538\Desktop\Codeblocks\fdsfaee\main.cpp|15|note: candidates are:|
C:\Users\L538\Desktop\Codeblocks\fdsfaee\main.cpp|8|note: A::A(int)|
C:\Users\L538\Desktop\Codeblocks\fdsfaee\main.cpp|8|note: candidate expects 1 argument, 0 provided|
C:\Users\L538\Desktop\Codeblocks\fdsfaee\main.cpp|5|note: A::A(const A&)|
C:\Users\L538\Desktop\Codeblocks\fdsfaee\main.cpp|5|note: candidate expects 1 argument, 0 provided|
||=== Build finished: 1 errors, 0 warnings (0 minutes, 1 seconds) ===|
然后我将下划线的内容替换为val(n),A::val(n)或者val(n),this->A::val(n),依旧报错。。。
啥意思?求给hint
|