[問題] 繼承習題問題
開發平台(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
--
◢ ◣ ▊ ▊ ▊ ▊ ◢◣ ◢◣ ▊ ▊ ▊███ ◣ ◣
◢█ L I N ◣ ▊ ▊ █◣ ▊◢ ◥◣ ▊ ▊ █◣ ▊ ▊ ▊ ▊ ▊
◥◤ ▊ ▇▇ ◥◤ ▊ ▊ ▊◥◣▊◥ ▊ ▊▊◥◣▊ ▊ ▊ ▊ ▊
▊ ▊▎ ▊ ▊ ▊ ◥▊ ◥◣ ▊ ▊▊ ◥▊ ▊ ▊ ▉ ▉
▊ ▎ ▊ ▊ ▊ ▊ ◥◣█▆▆▊▊ ▊ ▊ ▊ ◥█ ◤
ψ █▇▇ ▊ ▊ ▊◣▅▇◤▊ ▊▊ ▊ ▊ ▊ ▊
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.171.39.74
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1401635925.A.DF0.html
→
06/01 23:44, , 1F
06/01 23:44, 1F
→
06/01 23:44, , 2F
06/01 23:44, 2F
→
06/01 23:51, , 3F
06/01 23:51, 3F
討論串 (同標題文章)