What is the difference?
ClientList _userlist;
Adds an object of class ClientList
as an member of the class ChatMgr
_userlist
is an object in itself so, the compiler will call it's constructor when object of ChatMgr
is created. All initializations of _userlist
should occur in it's own constructor
or Initializer list
of the constructor.
ClientList *_userlist;
Adds an pointer to object of class ClientList
as an member of the class ChatMgr
*_userlist
should be point to something valid before using it because it is just a pointer and you need to point it to something meaninful to be able to use it.
Preferably, You should use initialize in Initializer List
of the Class ChatMgr
.
For the first one, can I just access to the all the data members inside of the class without initializing it?
As explained in Q1, Yes you can access the contents of _userlist
without initializing it because the initialization happens implicitly when compiler calls ClientList
constructor.