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 :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <string>
#include <vector>

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>
{
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<One<string>> x;
	vector<Two<string>> x2;

	One<string> css("one","two");
	Two<string> 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.
1
2
Two(T w, T w2, int n) : Two<T>::One(w,w2) {number = n;}
virtual const void Show () {cout << Two<T>::word << endl; cout << Two<T>::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
1
2
3
4
5
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.