Do different compilers handle shared_ptr assignment differently?

I am running into an issue in my code where I get a memory access violation error when trying to set a member variable of type shared_ptr on class Node equal to another shared_ptr which is passed into the setter method for this member variable called setMarkerPtr. I created a minimal reproducible example but to… Read More Do different compilers handle shared_ptr assignment differently?

State of underlying resource when a shared_ptr is created from the raw pointer?

This link about shared pointers states that You can pass a shared_ptr to another function in the following ways: … Pass the underlying pointer or a reference to the underlying object. This enables the callee to use the object, but doesn’t enable it to share ownership or extend the lifetime. If the callee creates a… Read More State of underlying resource when a shared_ptr is created from the raw pointer?

How to Store and retrieve the the correct Type of DerivedClass Pointer To/From Map of BaseClass Pointer

Hello i have question about Maps and Inheritance. I have Map of BaseClass Pointer: std::map<int,std::shared_ptr<Game>> GamesByID; and inserted Derived Class Pointer into it like: GamesByID.insert(make_pair(ID,std::make_shared<ActionGame>(ID,Title,Metacritic,Recommendations,Price,lvl))); now i wanted to count how many ActionGame Pointer i had in my map with somthing like that for (auto& e : GamesByID) { if(typeid(e) == typeid(SurvivalGame)){ ++count; }else{ cout… Read More How to Store and retrieve the the correct Type of DerivedClass Pointer To/From Map of BaseClass Pointer

unique_ptr can't instantiate class because it's abstract

I have an abstract class(Component) and this class should be owned by another class(GameObject). Every GameObject has a vector of components. Header: class Component; class GameObject{ public: GameObject(); virtual ~GameObject(); void addComponent(std::unique_ptr<Component> component); void addComponent(Component* component); void removeComponent(std::unique_ptr<Component> component); virtual void update(); std::string getInfo(); //return the first component of type T template<typename T> T* getComponent(){… Read More unique_ptr can't instantiate class because it's abstract