Skip to content

C++ : Convertion operators

September 24, 2010
  1: #include <iostream>
  2:
  3: class Test
  4: {
  5: public:
  6: 	// convertion from char const *
  7: 	Test( const char * _rhs )
  8: 		: _string( _rhs )
  9: 	{}
 10:
 11: 	// convertion to char const *
 12: 	operator char const * ()
 13: 	{
 14: 		return _string;
 15: 	}
 16:
 17: private:
 18: 	char const * _string;
 19: };
 20:
 21: int main()
 22: {
 23: 	Test instance("ala ma kota");
 24:
 25: 	std::cout << instance << std::endl;
 26:
 27: 	return 0;
 28: }
Advertisement

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.