我有两个简单的课程。我想要矢量显示结果,但没有显示数字。另一方面,当我尝试没有矢量的结果时,将显示结果。你能帮助我吗?谢谢你。
#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;
}