forked from Light-City/CPlusPlusThings
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathext_struct_func.cpp
More file actions
Latest commit
33 lines (30 loc) · 691 Bytes
/
Copy pathext_struct_func.cpp
File metadata and controls
33 lines (30 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<iostream>
#include<stdio.h>
usingnamespacestd;
structBase {
int v1;
// private: //error!
int v3;
public://显示声明public
int v2;
virtualvoidprint(){
printf("%s\n","Base");
};
Base(){cout<<"Base construct"<<endl;};
virtual~Base(){cout<<"Base deconstruct"<<endl;};
};
structDerived:Base {
Derived(){cout<<"Derived construct"<<endl;};
virtual~Derived(){cout<<"Derived deconstruct"<<endl;};
public:
int v2;
voidprint(){
printf("%s\n","Derived");
};
};
intmain() {
Base *b=newDerived();
b->print();
delete b;
return0;
}