Reputation: 55
I'm using Qt/C++.
So I have a vector :
QVector<Room> rooms; //does everything like normal vector from what I've seen(I hope)
My room class looks something like this :
class Room{
Textbox *t;
//other stuff
}
When room is added, vector makes a copy of the room passed by reference and pushes copy in :
void Floor::AddRoom(Room &_room, QWidget *_window)
{
rooms.push_back(_room);
}
My question is what will happen to Textbox pointer that belongs to _room
since it is pointing at something before copy if it is made? Will my new pushed room had it's *t
pointing to the same address/object as _room
that was passed by reference or will it became nullptr?
I read documentation but couldn't find anything about what happens to pointers when copy of object is pushed to vector. Thanks in advance.
Upvotes: 0
Views: 75
Reputation: 2780
Yes, it's going to point to the same object as originally if you don't provide your own copy constructor, because the value of the pointer is copied, not the object the pointer points to.
Upvotes: 2