标签:iostream sys ios system def this string str child
#include <iostream>
#include <string>
using namespace std;
class Object{
private:
string ms;
public:
Object ( string s ){
cout << "Object ( string s ) : " << s << endl;
this->ms = s;
}
~Object (){
cout << "~Object() : " << ms << endl;
}
};
class Parent : public Object{
private:
string ms;
public:
Parent () : Object( "Default" ){
cout << "Parent() " << endl;
this->ms = "Default";
}
Parent ( string s ) : Object( s ){
cout << "Parent ( string s ) : " << s << endl;
this->ms = s;
}
~Parent (){
cout << "~Parent() : " << ms << endl;
}
};
class Child: public Parent{
private:
Object mO1;
Object mO2;
string ms;
public:
Child () : mO1( "Default 1" ), mO2( "Default 2" ){
cout << "Child() " << endl;
this->ms = "Default";
}
Child ( string s ) : Parent ( s ), mO1( s + " 1" ), mO2( s + " 2" ){
cout << "Child( string s ): " << s << endl;
this->ms = s;
}
~Child (){
cout << "~Child() : " << ms << endl;
}
};
int main ( int argc, char** argv ){
Child c;
Child cc( "cc" );
system ( "pause" );
return 0;
}
标签:iostream sys ios system def this string str child
原文地址:http://blog.51cto.com/chen0547/2059220