Appending objects

I have a class which consist of an vector..

I want to create a merge function which appends a object to another object, the idea is that the vector which on object has shall be appended to the primary object and the function has to return the appended object.


obj1.merge(obj2)
return obj1 //with obj2 appended


How would i create this function??


are obj1 and obj2 of the same class?
yes
use std::vector.push_back().
From your sample code, I understand that merge is a member function of the objects. Right?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Test
{
public:
	void merge(Test &);
private
	vector<Test> vec;	
};

Test::merge(Test &obj2)
{
	vec.push_back(obj2);	//push obj2 to vector
}

int main()
{
	Test obj1;
	Test obj2;
	
	obj1.merge(obj2);
}
the class contain a vector of ints, it does not work.
Is it that you want to merge the 2 integer vectors of obj1 and obj2?
Well..
I've solved it using the the insert.
Good to know.
Topic archived. No new replies allowed.