#include #include template class MethodReturn { public: MethodReturn() {} MethodReturn( const R ReturnValueIN ): ReturnValue(ReturnValueIN) {} MethodReturn( const R ReturnValueIN, const std::string& rReasonIN ): ReturnValue(ReturnValueIN), ErrorDescription(rReasonIN) {} virtual ~MethodReturn() {} void swap( MethodReturn& rOtherIN ) { std::swap( ReturnValue, rOtherIN.ReturnValue ); std::swap( ErrorDescription, rOtherIN.ErrorDescription ); } MethodReturn( const MethodReturn& rOtherIN ) { ReturnValue = rOtherIN.ReturnValue; ErrorDescription = rOtherIN.ErrorDescription; } MethodReturn& operator = ( const MethodReturn& rOtherIN ) { MethodReturn temp(rOtherIN); swap(temp); return *this; } virtual R Return( void ) { return ReturnValue; } virtual std::string What( void ) { return ErrorDescription; } private: R ReturnValue; std::string ErrorDescription; }; MethodReturn f1( int* iPtrIN ) { if ( NULL == iPtrIN ) return (MethodReturn::MethodReturn(false, "Bad Argument- Input pointer is NULL!")); return (MethodReturn::MethodReturn(true)); } MethodReturn f2( void ) { return (MethodReturn::MethodReturn(true)); } MethodReturn f3( void* vpPtrIN ) { if ( NULL == vpPtrIN ) return (MethodReturn::MethodReturn("Error!!!", "Bad Argument- Input pointer is NULL!")); return (MethodReturn::MethodReturn("No Error.")); } void main( void ) { MethodReturn bRet; bRet = f1( NULL ); std::cout << "Returned: " << bRet.Return() << std::endl; std::cout << "Reason: " << bRet.What() << std::endl; bRet = f2(); std::cout << "Returned: " << bRet.Return() << std::endl; std::cout << "Reason: " << bRet.What() << std::endl; MethodReturn strRet = f3( NULL ); std::cout << "Returned: " << strRet.Return() << std::endl; std::cout << "Reason: " << strRet.What() << std::endl; }