function without return type.

ravi_garg's Avatar, Join Date: Oct 2007
Newbie Member
how the operator function i.e. operator const char * const() has no return type but still returning and the code compile successfully.

Code:
namespace Edu {
	class TestBase {
		public:
			TestBase() { }
			const char * const GetMessage() const { return "Edu::TestBase()" ; }
		        operator const char * const () const { return this->GetMessage() ; };
	};

	class TestDerived : public TestBase {
		public:
			TestDerived() { }
			operator const char * const () const { return "Edu::TestDerived()" ; };
	};

	void Funct( const char * const = "Hello, C++" );
};

void Edu::Funct( const char * const msg ) {
	std::cout << msg << std::endl;
}

int main() {

	const Edu::TestBase ob_base ;
	const Edu::TestDerived ob_derived ;

	std::cout << ob_base << std::endl;
	std::cout << ob_derived << std::endl;

	Edu::Funct( ob_derived ) ;
	Edu::Funct( ob_base ) ;
	Edu::Funct( "Hi from C++ !!" );

	return 0;

}
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Your compiler does not consider that as an Error.