I have two simple classes. I want with vector show result, but number is not showed. On the other hand, when I try result without vector, result will be show. Can you help me? Thank you.
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
using namespace std;
template<typename T>
class One
{
protected:
T word;
T word2;
public:
One() {word = "0"; word2 = "0";}
One(T w, T w2) {word = w; word2 = w2;}
virtual const void Show() {cout << word << endl; cout << word2 << endl;}
};
template<typename T>
class Two : public One<T>
{
private:
int number;
public:
Two() {number = 0;}
Two(T w, T w2, int n) : One(w,w2) {number = n;}
virtual const void Show () {cout << word << endl; cout << word2 << endl; cout << number << endl; }
};
int main ()
{
One<string> *idk;
Two<string> *something = new Two<string>("asd","aa",1);
idk = something;
idk->Show(); // OK - asd, aa, 1
vector<One<string>> arr;
arr.push_back(*idk);
arr.at(0).Show(); // WRONG - asd,aa
return 0;
}