C++ – Calling constructor from another class

cconstructorsse

If I have a class like this:

typedef union { __m128 quad; float numbers[4]; } Data

class foo
{
public:
    foo() : m_Data() {}

    Data m_Data;
};

and a class like this:

class bar
{
public:

   bar() : m_Data() {}

   foo m_Data;
}

is foo's constructor called when making an instance of bar?

Because when I try to use bar's m_Data's quad in bar it seems to be uninitialized, even though it has values in numbers[4]. :\

Specifically, this crashes:

m_Data.quad = _mm_mul_ps(m_Data.quad, a_Other.m_Data.quad)

Any help would be appreciated. 🙂

Best Answer

You have to declare your constructor to be public, otherwise you are not allowing anyone to instantiate your class if you declare it as private member.