I have the following C++-class:
// Header-File
class A
{
public:
A();
private:
B m_B;
C m_C;
};
// cpp-File
A::A()
: m_B(1)
{
m_B.doSom
How about using technique described in this QA?
Prevent calls to default constructor for an array inside class
std::aligned_storage::type
Or, you also can consider using of union
. AFAIK, unions will be initialized only with first named member's constructor.
For example,
union
{
uint8_t _nothing = 0;
C c;
};
According to the standard mentioned in the QA, c
will be zero-initialized, and its constructor will not be called.