多数のバニラchar*
ポインターだけでなく、オブジェクト メンバーも定義されている構造体があります。このような構造体を静的に初期化しようとすると、コンパイラ エラーが発生します。
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
引数のない public デフォルト コンストラクターがあるため、これが問題になるとは思いませんでした。しかし、これを (VS を使用して) コンパイルしようとすると、次のエラーが発生します。
error C2248: 'SomeObject::SomeObject' : cannot access private member declared in class 'SomeObject'
理由はありますか?
更新: SomeObject の定義は次のとおりです
class SomeObject
{
void operator=(const SomeObject&);
SomeObject(const SomeObject&);
public:
SomeObject()
{
// etc
}
// members snipped
}