mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-02-03 10:33:25 +08:00
update
This commit is contained in:
33
basic_content/struct/ext_struct_func.cpp
Normal file
33
basic_content/struct/ext_struct_func.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user