In the past, I always created this map:
class TestClass
{
private:
std::map<int,int> *mapA;
};
TestClass::TestClass
{
mapA = new std::map<int,int>();
}
TestClass::~TestClass
{
mapA->clear();
delete mapA;
}
So now I read throughout Stackoverflow: avoid pointers as often as possible
Currently I want to create a map without a pointer and a new one (there is no need to delete the object yourself and there is less risk of a memory leak)!
class TestClass
{
public:
TestClass() : mapA()
{};
private:
std::map<int,int> mapA;
};
Are further steps required to properly create a map?
Thanks for any help and / or clarification!
source
share