c++ 继承与静态成员

来源:互联网 发布:闲鱼淘宝介入要多久 编辑:程序博客网 时间:2024/05/17 23:24



#include<iostream>using namespace std;  class Base{  public :        static int getValue()        {             static int i = 0;            i += 1;            cout << i << endl;            return i;        }};class Derived : public Base{public:void getV(const Derived &derived_obj);};void Derived::getV(const Derived &derived_obj){   derived_obj.getValue();   getValue();}int main(){  Base::getValue();  Derived::getValue();  Derived d1;  Derived d2;  d2.getV(d1);  return 0;}

输出:

pateo@pateo-B86N53X:~/work/study$ g++ main.cc -o mainpateo@pateo-B86N53X:~/work/study$ ./main1234