This has been one of my deepest forays into C++ programming, having been scared off in the past by the arcana of memory management . I 'cured' my memory management problems by incorporating garbage collection thanks to Hans Boehm. (OK I don't like writing destructors or remembering when to call them.)
I now however have run into an interesting problem with function overloading in an inherited class.
I have a situation that looks something like this:
I did not label setdims() as virtual since the behavior I want is for setdims to be overloaded for a class of type Bar and the Foo's setdims() to be hidden. However what happens when I call the inherited function func1() for a class of type Bar? (e.g. Bar x ; x.func1() ; ) Apparently with MS's compiler it calls Foo's setdims() and not Bar's setdims(). This is not the behavior I want. Basically I'd like to reuse Foo's code, since the only major functional change for many methods is what get's allocated in the function setdims(). Thus I'd like to call the parent's class func1() but have it call the overloaded setdims() not the parent's setdims().Code:class Foo { public: void setdims() { ..... } void func1 () { setdims() ; } } ; /* end class Foo */ class Bar: public Foo { public: void setdims() { ..... /* different implementation */ } } ; /* end class Bar */
How do I fix this? Do I need the virtual descriptor here? Is this what is supposed to happen?
Thanks in advance for your help.