※ 引述《APE36 (PT乡民)》之铭言:
: 开发平台(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
我没看过 iostream.h 还有没有用 namespace 可以直接用 cout 跟 endl
还蛮奇怪的
#include <iostream>
using namespace std;
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;
// x = 10, y = 20, a = 30, b = 40, c = 50
b.CB::x = 5;
// x = 5, y = 20, a = 30, b = 40, c = 50
b.a = 1;
// x = 5, y = 20, a = 1, b = 40, c = 50
b.CA::a = 5;
// x = 5, y = 20, a = 5, b = 40, c = 50
b.c = 2;
// x = 5, y = 20, a = 5, b = 40, c = 2
cout<< "result= "<< b.getM()<< endl;
cout<< "result= "<< b.getN()<< endl;
}
b.CB::x 这是正式用法吗?