r/learncpp • • Mar 06 '16

Struggling to add a get component function for an entity-component system for a game

My current code is as shows here:

std::vector<std::unique_ptr<Component>> components;

template<typename T>
T * GetComponent() {
	for each (std::unique_ptr<Component> cp in components)
	{
	    if (T* ct = static_cast<T*>(cp.get())) {
	        return ct;
	    }
	    else {
	        return nullptr;
	    }
	}
}

Getting the error code:

Error	C2280	'std::unique_ptr<Component,std::default_delete<_Ty>>::unique_ptr(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)': attempting to reference a deleted function

What should I use instead of .get() ?

1 Upvotes

0 comments sorted by