[haXe] overloading parent with different type

Martin Wood flashdev at relivethefuture.com
Fri Apr 7 22:33:04 CEST 2006


cornel wrote:
>> this seems weird to me, i know you cant overload normal functions in C++ based
>> solely on return types, does this compile?
> 
> compiles happily (vc++ 2005)
> it wont compile if you have something like
> 
> class A{
> public:
> 	int f(){return 0;}
> 	std::string f(){return "lol";}
> };
> 
> err: 'std::string A::f(void)' : overloaded function differs only by
> return type from 'int A::f(void)'
> 
>> and what happens if i dont use the
>> return type on a call to f() on an instance of B ?
>>
>> B instance;
>> instance.f();
> 
> it returns 'hi', as expected
> 
>> what happens if i have a pointer to a B, but declared as type A and call f
>> without using the return type?
>>
>> A *instance;
>> instance = new B;
>> instance->f();
> 
> it returns 0
> 

thanks, saves me from installing a c++ compiler :)

sorry to not answer your question but it might help shed some light on what your 
expected behaviour is and why it doesnt happen (and maybe cant happen)

just to complete the example, in both of those cases can you call both versions 
of f just by assigning the returned value to either a string or an int?

thanks,

Martin




More information about the Haxe mailing list