[問題] 繼承習題問題

作者: APE36 (PT鄉民)   2014-06-01 23:18:42
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
補充說明(Supplement):
#include <iostream.h>
class CA{
public:
CA(){a=30; b=40; c=50; }
int a, b, c;
};
class CB: public CA{
public:
CB(){ x=10; y=20;}
int x, y;
int getM(){ return x*y; }
int getN(){ return CA::a*CA::b*c/x; }
};
main()
{
CB b;
b.CB::x = 5;
b.a = 1;
b.CA::a = 5;
b.c = 2;
cout<< "result= "<< b.getM()<< endl;
cout<< "result= "<< b.getN()<< endl;
}
請問這兩個答案輸出
會100,80
不懂他的trace code
希望有人肯解析一下,桑Q
作者: diabloevagto (wi)   2014-06-01 23:44:00
你找本書看比較實在還是你那邊不懂?b.CA::a 這意思是指向繼承的 CA 內的 a

Links booklink

Contact Us: admin [ a t ] ucptt.com