1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

function without return type.

Discussion in 'C' started by ravi_garg, Oct 9, 2007.

  1. ravi_garg

    ravi_garg New Member

    Joined:
    Oct 9, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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;
    
    } 
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Your compiler does not consider that as an Error.
     

Share This Page