Question

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. :)

Was it helpful?

Solution

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.

OTHER TIPS

Looks good for me. foo and bar are non-POD types because they have a constructor, so their members are guaranteed to be initialized after constructing.

Maybe the data is overwritten later through a memory leak?

How do you create the instance of bar?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top