1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

function without return type.

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

  1. ravi_garg

    ravi_garg New 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;
    
    } 
     
  2. shabbir

    shabbir Administrator Staff Member

    Your compiler does not consider that as an Error.
     

Share This Page