Hello guys this is actually due tonight at 12. I have been working on this for 2 hours now. I am having trouble understanding Class Inheritance. My program works completely fine in the event that a user enters 0, 0 ,0 for height, width, and length; however, when they enter a value greater than 0 for each parameter is where my problem occurs. I went into debug and it appears that as soon as my last cout statements occure (when I call my getters) my original inherited fields get set back to 7 and 8. I tested with values 10, 10, and 10 and they do successfully get set to that but once my cout statements occur at the end of the app, they get set back to 7 and 7. Why is this?
The problem is your Prism constructor will call the base class's (Triangle's in this case). This will reset your width and height members. You'll need to use an initializer list to call Triangle's constructor manually inside Prism's constructor.
firedraco, could you perhaps show me an example? either yours or a point in the right direction. I can understand what you are saying I just don't know how to get there. My Prism() seems to call the correct default constructor of Triangle(). I dont know why Prism(parameters) does not call Triangle(parameters) instead of triangle()
although you seem to be calling parameterized constructor of Triangle() by writing parameterized constructor of Prism class, infact only default construct of Triangle class is calling in your program. So as firedraco stated, call parameterized constructor of base class Triangle() from the derived class Prism() explicitly using member initializer list as below:
Now Triangle(parameters) will be called.
But your answer will be same as passing 0, 0,0 for height, length and width. To avoid this error you have to erase base class default constructor Triangle().