// hello_ansi.cpp // // Hello world in ANSI C++ // // ANSI C++ method of includes #include // C++ Standard Library STL string class #include // specification of Hello_Ansi class Hello_Ansi { // public interface public: Hello_Ansi(); ~Hello_Ansi(); void Set_data ( const char * d ); void Set_data ( const std::string & d ); const char * Getc_data ( void ) const; const std::string & Gets_data ( void ) const; void Show ( void ) const; unsigned int size ( void ) const; // private interface private: std::string data; }; // Implementation of Hello_Ansi Hello_Ansi::Hello_Ansi() { data = ""; std::cout << "Constructed Hello_Ansi" << std::endl; } Hello_Ansi::~Hello_Ansi() { std::cout << "Destructed Hello_Ansi" << std::endl; } void Hello_Ansi::Set_data ( const char * d ) { data = d; } void Hello_Ansi::Set_data ( const std::string & d ) { data = d; } const char * Hello_Ansi::Getc_data ( void ) const { return ( data.c_str() ); } const std::string & Hello_Ansi::Gets_data ( void ) const { return ( data ); } void Hello_Ansi::Show ( void ) const { std::cout << data << std::endl; } unsigned int Hello_Ansi::size ( void ) const { return ( data.size()+1 ); } int main ( void ) { Hello_Ansi h1; Hello_Ansi h2; std::string s = "Hello H2"; h1.Set_data( "Hello World H1" ); h2.Set_data( s ); h1.Show(); h2.Show(); std::cout << "sizeof h1 = " << sizeof(h1) << std::endl; std::cout << "sizeof h2 = " << sizeof(h2) << std::endl; std::cout << "size of h1 = " << h1.size() << std::endl; std::cout << "size of h2 = " << h2.size() << std::endl; return(0); }