Vector storage problem

I'm trying to store a value passed through a function argument into a vector. Everytime the method is called "name" changes and so do the values stored in _groups. How can I fix this?

1
2
3
4
5
6
7
8
9
10
11
12
13
void GroupDB::addGroup(char* name)
{
	GroupInfo* tempGroup = new GroupInfo(name, _nextGid++);

	_groups.push_back(tempGroup);
	for(int i = 0; i < _size; i++)
	{
		cout << (*_groups.at(i)).getGroupName();
	}
	
	// IGNORE THIS cout << "[" << (*_groups.at(_size)).getGroupName() << "]"<< " with [" << _nextGid - 1 <<"] is added." << endl;
	_size++;
}


So if name was "Carl" for the first input, it would cout "Carl"
and if the second input was "Greg" the second cout would be "GregGreg"

Thanks in advance!
Last edited on
Your `GroupInfo' is doing a shallow copy of the name parameter
Also, you probably shouldn't be using new http://www.cplusplus.com/forum/general/138037/#msg731921
Topic archived. No new replies allowed.