[haXe] overloading parent with different type
cornel
tcornel at gmail.com
Fri Apr 7 22:45:36 CEST 2006
int main(){
A *instance;
instance = new A;
std::cout<<instance->f();
instance = new B;
std::cout<<instance->f();
}
it returns 0 in both cases.
int main(){
A *ainstance = new A;
std::cout<<ainstance->f();
B *binstance = new B;
std::cout<<binstance->f();
}
it returns 0 and "hi"
On 4/7/06, Martin Wood <flashdev at relivethefuture.com> wrote:
> 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
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>
More information about the Haxe
mailing list