CPlusPlusThings/basic_content/struct/ext_struct_func.cpp
Light-City 8edbbbc5a2 update
2019-11-05 16:56:07 +08:00

34 lines
691 B
C++

#include<iostream>
#include<stdio.h>
using namespace std;
struct Base {
int v1;
// private: //error!
int v3;
public: //显示声明public
int v2;
virtual void print(){
printf("%s\n","Base");
};
Base(){cout<<"Base construct"<<endl;};
virtual ~Base(){cout<<"Base deconstruct"<<endl;};
};
struct Derived:Base {
Derived(){cout<<"Derived construct"<<endl;};
virtual ~Derived(){cout<<"Derived deconstruct"<<endl;};
public:
int v2;
void print(){
printf("%s\n","Derived");
};
};
int main() {
Base *b=new Derived();
b->print();
delete b;
return 0;
}