#include<iostream>
#include<vector>
#include "BaseDerived.h"
#include "BaseDerived2.h"
#include "BaseDerived3.h"
usingnamespace std;
int main()
{
/*Base is a non-derived class because it does not inherit from anybody.
C++ allocates memory for Base, then calls Base’s default constructor
to do the initialization. */
Base cBase(3);
cout<<cBase.m_nValue << endl;
cout << cBase.m_nValue << endl;
cout << cBase.GetName() << endl;
// cout << "pBase is a " << pBase->GetName() << " and has value " << pBase->GetValue() << endl;
/* Derived is really two parts: a Base part, and a Derived part.
When C++ constructs derived objects, it does so in pieces,
starting with the base portion of the class.
Once that is complete, it then walks through the inheritance tree and
constructs each derived portion of the class.*/
/* Derived cDerived(1,2.5);
cout << cDerived.m_nValue << endl;
cout << cDerived.m_dValue << endl;
cout << cDerived.GetName() << endl;
cout << "Constructing A: " << endl;
A cA;
cout << "Constructing B: " << endl;
B cB;
cout << "Constructing C: " << endl;
C cC;
//cout << "Constructing D: " << endl;*/
//D cD;
// Gamma c;
Derived cDerived(1,5.0);
// These are both legal!
Base& rBase = cDerived;
Base* pBase = &cDerived;
Derived* pDerived = &cDerived;
cout << "cDerived is a " << cDerived.GetName() << " and has value " << cDerived.GetValueDoubled() << endl;
cout << "rBase is a " << rBase.GetName() << " and has value " << rBase.GetValue() << endl;
cout << "pBase is a " << pBase->GetName() << " and has value " << pBase->GetValue() << endl;
cout << "pDerived is a " << pDerived->GetName() << " and has value " << pDerived->GetValueDoubled() << endl;
/*vector<Base> vBase;
vBase.reserve(5);
for(int i=0;i<5;i++)
vBase.push_back(Base(i*2.0));
cout << vBase[2].GetName()<< " and has value " << vBase[2].GetValue() << endl;*/
return 0;
}
can you beat my lecturer and explain it in less than 4 slides :p
when I try uncommenting line 17 in main it doesn't like it.
I found the learncpp.com thing so no need to gtfm :p
Guess I need to stew on it, too late for my brain maybe, zzzzzz.