c++ - Virtual method of copy of Pointer not working -


i'm having problem overriding methods on c++

first, worked fine, then, made changes keep code more "organized" , share on github.

after doing oo changes, facilitate , make easier understand, code stopped working, , because of weird thing.

viewgroup class extends view, , has method hittest override view.

so, basicaly: if call hittest, must running on viewgroup (if it's viewgroup), or on view;

thats ok, put virtual on method, , if direcly run on viewgroup, in fact runs hittest viewgroup,

but, if create new pointer, , try run, doesen't runs hittest on viewgroup anymore, runs on view. facilitate understanding:

viewgroup *v = new viewgroup();  view *t = v;  v->hittest(100,100); // runs on viewgroup (ok) t->hittest(100,100); // runs on view (not ok) 

update:

viewgroup.h: https://www.dropbox.com/s/a3lqbm73qlxds3i/viewgroup.h

viewgroup.cpp: https://www.dropbox.com/s/vxbqsh6ol430x4p/viewgroup.cpp

view.h: https://www.dropbox.com/s/tcrb75dmx3v6pgq/view.h

view.cpp: https://www.dropbox.com/s/4sb82d6thqz34od/view.cpp

update 2:

the problem caused dumb mistake on declaration of methods. one, declared hittest(int x, int y) , other, hittest(long x, long y).

it happend while "cleaning" , improving code.

but, it's weird, since working before copied object, , after copying, not more...

the signatures of two-argument versions of hittest different. if you're coding c++11, use override keyword overrides of virtual functions ... spare sort of grief.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -