Jump to content

Virtual method output of base class vs. child implementation.


Recommended Posts

Using SciWare's GOOP Developer 2.3 I have made ClassA and a child class B, which both have their own increment() virtual method. The base class method increments data member num by 1, and the B class increment data member num by 3. Both methods give incremented value as an output. The data member num has also a getter.

I have made the demo below to illustrate my question.

post-11857-126780088462_thumb.gif

The two instances of the ClassA and B are called by their own implementation of increment and after incrementation num value is get. The base class ClassA part works as intended: num value is incremented and the value gotten from the increment method is the same as the value gotten from the getter. The child class B part, however, doesn't work the same way: the num value is incremented, but increment method return 0, although the getter shows that the value is indeed incremented in each loop execution.

Here is the front panel after while loop has executed 3 times:

post-11857-12678008813_thumb.jpg

So why the 0 output?

Link to comment

Do you have a "num" field in both the parent and child?

Could it be that you're setting the parent value and reading the child value or vise versa?

Yes, both should have num field as B class inherits it from its parent class classA, which has a num field.

I don't quite see what you mean. How could the instances write each other's data members, if they are clearly in their own separate sequences?

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.