Static initialization of a struct with class members

Posted by JS Bangs on Stack Overflow See other posts from Stack Overflow or by JS Bangs
Published on 2010-05-18T20:54:22Z Indexed on 2010/05/18 21:00 UTC
Read the original article Hit count: 183

I have a struct that's defined with a large number of vanilla char* pointers, but also an object member. When I try to statically initialize such a struct, I get a compiler error.

typedef struct 
{
    const char* pszA;
    // ... snip ...
    const char* pszZ;

    SomeObject obj;
} example_struct;

// I only want to assign the first few members, the rest should be default
example_struct ex = { "a", "b" };

SomeObject has a public default constructor with no arguments, so I didn't think this would be a problem. But when I try to compile this (using VS), I get the following error:

error C2248: 'SomeObject::SomeObject' : cannot access private member declared in class 'SomeObject'

Any idea why?

© Stack Overflow or respective owner

Related posts about c++

Related posts about struct