#include <iostream>
#include <string>
using namespace std;
class MyCla1
{
char *str;
public:
MyCla1( char *s );
~MyCla1()
{
cout << "Destructor: Destroying=> " << str << "\n";
delete str;
}
void print()
{
cout<<" --- printed by => "<<str<<endl;
}
};
MyCla1::MyCla1( char *s )
{
cout << "Constructor: Initializing=>" << s << "\n";
str=new char[strlen(s)+1];
strcpy( str, s );
}
MyCla1 I0( "Global I0" );
int main()
{
I0.print();
MyCla1 I1( "Function_Local I1" );
int cond=2;
I1.print();
while(cond)
{
cout << "In block.\n";
MyCla1 I2( "Block_Local I2" );
I2.print();
static MyCla1 I3( "Static I3" );
cond--;
}
cout << "Exited block.\n";
return 0;
}
SMILET
哆啦的时光机
相关分类