main.cpp

来自「C++北航内部教学」· C++ 代码 · 共 62 行

CPP
62
字号
#include <iostream>
#include <stdlib.h>

using namespace std;
class A
{
public:
   A(){ n=5; }
   void g()
   { 
      cout << "ggg" << endl;
      cout <<"The address of n is:" <<(unsigned long)&n <<endl;
   }
private:
   int n;
};

class B
{
public:
   B(){ m=5; }
   void f()
   { 
      cout << "fff" << endl;
      cout <<"The address of m is:" <<(unsigned long) &m <<endl;
   }
private:
   int m;
};

class C : public A, public B
{
public:
   C(){ u=5; }
   void show()
   {
      A::g();
      B::f();
      cout <<"The address of u is:" << (unsigned long)&u <<endl;
      cout << "The size of this pointer is:" << sizeof(this) <<endl;
      cout << "The value of this pointer is:" << (unsigned long)this <<endl;
    }
private:
   int u;    
};
 
int main(int argc, char *argv[])
{
  C c;
  
  c.show();
  
  cout <<"/////////////////////////////////////////////" <<endl;
  
  C c2;
  
  c2.show();
  
  system("PAUSE");	
  return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?