conjunction two vectors

Hello, I want to conjunction two vectors, but when I try to write result on the screen I get result without int number, which is in Two<T>. I want to get result: one two three four 50
Can you help me, how to fix it? Thank you :)

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354`` ``````#include #include #include using namespace std; template 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 class Two : public One { protected: 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 () { vector> x; vector> x2; One css("one","two"); Two csss("three","four",50); x.push_back(css); x2.push_back(csss); x.insert(x.end(),x2.begin(),x2.end()); for (int i = 0; i < x.size(); i++) { x.at(i).Show(); } cin.get(); cin.get(); return 0; }``````
To make the code compile I had to add Two<T>:: in a few places on line 28 and 29.
 ``12`` ``````Two(T w, T w2, int n) : Two::One(w,w2) {number = n;} virtual const void Show () {cout << Two::word << endl; cout << Two::word2 << endl; cout << number << endl; }``````

After that it compiles and I get the output:
 ```one two three four```
Hmm.. Yes, but I need get output
 ``12345`` ``````one two three four 50``````

I need just conjunction One<T> and Two<T> to one itself vector.
Ah, I missed that. x is storing objects of type One<string> and can't store objects of any other type. What happens when you try to add a Two<string> object to x is called slicing. Only the One<string> part of the Two<string> object will be copied and inserted into x.

A One<string> pointer can point to a One<string> object or to a Two<string> object, so if you have a vector of One<string> pointers (or smart pointers) you can store pointers to both types in the same vector. That is probably what you'll have to do.
Topic archived. No new replies allowed.