Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   function without return type. (http://www.go4expert.com/forums/function-return-type-t6754/)

ravi_garg 9Oct2007 19:38

function without return type.
 
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 9Oct2007 21:04

Re: function without return type.
 
Your compiler does not consider that as an Error.


All times are GMT +5.5. The time now is 01:19.