Should we initialise queue and maps of a class in constructor

I have a class which has queue and map like below where astruct is a structure and aclass is a class. Should i initialise these in a constructor? Is so how do i do this? Thanks in advance

class A
{
queue<astrct*> m_testQueue;
map<int,aclass*> m_testmap;
A()
{};
}
Your constructors should ALWAYS construct everything fully that can't be default constructed by themselves.

Your standard containers such as queue and map will construct themselves to be empty.
I'll word it a bit differently: Your construct WILL always construct any sub-objects. If you don't specify a constructor via an initializer list*, they will be default constructed.

But as salem c said, this just means m_testQueue and m_testmap will be empty containers by default.

* https://www.geeksforgeeks.org/when-do-we-use-initializer-list-in-c/
Last edited on
Thanks, that answers my question.
Topic archived. No new replies allowed.