sergey.pozhidaev Posted November 6, 2013 Share Posted November 6, 2013 incorrect reference work in overrided subclass member functions, my actions: 1.create base class "a" 2.add member function "func1" in "a" 3.create subclass "b : a" 4.override "func1" in "b" 5.get bug in reference value class a { void func1(int &val){ val = 5; } }; class b : a { void func1(int &val){ val = 9; } }; class c{ b b_inst; c(){ b_inst = new b(); int value = -1; b.func1(value); //value = 0, why? } }; Link to comment
sebastianbah Posted November 7, 2013 Share Posted November 7, 2013 Hi, It seems that you try to call func1() from b instead of class instance.Please, try to replace b.func1(value); -> b_inst.func1(value); In this case it should work correctly. Link to comment
Recommended Posts