don't know how to print with template

hi! i need to demonstrate this program by creating and printing Pair objects that contain five different kinds of pairs, such as <int,string> and <float,long>. But i don't have any idea how to print it on the int main(). i'm a newbie. Can you guys help me? Thanks

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>
using namespace std;

template <typename T1, typename T2>
class Pair {
public:
	Pair(T1, T2);
	void setFirst(T1);
	void setSecond(T2);
	T1 getFirst() const;
	T2 getSecond() const;
	void print() const;

private:
	T1 object1;
	T2 object2;
};

template <typename T1, typename T2>
Pair<T1,T2>::Pair(T1 first,T2 second){
	object1 = first;
	object2 = second;
}

template <typename T1, typename T2>
void Pair<T1,T2>::setFirst(T1 first){
	Pair<T1,T2>::object1=first;
}

template <typename T1, typename T2>
void Pair<T1,T2>::setSecond(T2 second){
	Pair<T1,T2>::object2=second;
}

template <typename T1, typename T2>
T1 Pair<T1,T2>::getFirst() const{
	return object1;
}

template <typename T1, typename T2>
T2 Pair<T1,T2>::getSecond() const{
	return object2;
}

template <typename T1, typename T2>
void Pair<T1,T2>::print() const{
	cout << "Object 1 : " << object1 << endl;
	cout << "Object 2 : " << object2 << endl;
}

int main () {
	//help me in here
	cin.get();
}
Compare that to this:
1
2
3
4
5
int main() {
  std::vector<double> foo;
  std::cout << foo.size();
  return 0;
}

std::vector and Pair are both templates.
Both have member functions (size and print, respectively).
My main() uses a concrete object foo, which is a vector of doubles.
What should your main() use?
Thanks for replying. This is my main()
I can print what i want but i only use 1 function which is Pair(T1, T2).
I want to know how to use my other function such as setFirst and getFirst. Any suggestion?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main () {
	Pair <int, double> pa(123456, 32.5674);
	pa.print(); 
	
	Pair <string, int> pi("Brain", 98);
	pi.print();
	
	Pair <float, char> pu(23.5, '*');
	pu.print();
	
	Pair <char, float> pe('#', 4.32);
	pe.print();
	
	Pair <long int, string> po(1234567891, "Error");
	po.print();
	
	cin.get();
}
Have I misunderstood the question?

1
2
3
4
5
	Pair <int, double> pa(123456, 32.5674);
	pa.print();
	pa.setFirst(25);
	pa.setSecond(25.25);
	pa.print();
Topic archived. No new replies allowed.