Passing STL vectors of type object

Hey forums.

I'm attempting to pass a std::vector<object> memory address to a method and then assign that adress to a std::vector<object>* pointer in the class where the method is placed. When i attempt to write
this->my_object_vector_ptr = my_passed_object_vector_ptr
I receive a sea of errors and my program crashes...

Init class variables in header:
1
2
	std::vector<sf::Sprite> g_sprite_array;
	std::vector<sf::RectangleShape> g_rect_array;


Init class method
1
2
	update update_obj(this->m_window_ptr);
	update_obj.m_init_loop(&this->g_sprite_array, &this->g_rect_array);


Update class variables in header:
1
2
	std::vector<sf::Sprite> *g_sprite_array_ptr;
	std::vector<sf::RectangleShape> *g_rect_array_ptr;


Update class method
1
2
3
4
5
void update::m_init_loop(std::vector<sf::Sprite> *g_sprite_ptr, std::vector<sf::RectangleShape> *g_rect_ptr)
{
	this->g_sprite_array_ptr = g_sprite_ptr;
	this->g_rect_array_ptr = g_rect_ptr;
}


The type of objects the vector takes shouldn't really matter. Shouldn't the pointer point to the start of the array even in heap allocation?

Thanks in advance!
Last edited on
I'm not sure why you even need pointers at all here - why not use references?

Are you ensuring that those vectors live long enough to be used through the pointers?
Topic archived. No new replies allowed.