jeudi 11 novembre 2021

Initialize members at later point without using pointers possible? C++

Say I have a class A, that consumes messages of a network. Class A has 2 members b and c of corresponding type B and C. The members can only be initialized with information, that comes from the network.

Is there a way to initialize the members at a later point, without having the members to be of type B* and C* (initialize with nullptr and set the wanted value later)?

I feel like in such a scenario the design has a flaw, but I am still asking myself what the best practice would be, as I am kind of sluggish when using pointers after reading Why should I use a pointer rather than the object itself? ?

Aucun commentaire:

Enregistrer un commentaire