2
2b|!2b==?
I have a class that contains C structs as member variables. By C
structs, I mean they cannot have ctors/dtors because they have C linkage
(extern "C").
For eg:
MyClass
{
//Impl
private:
MyStruct1 m_struct ;
};
//In C code, I could declare/define/initialize the m_struct variable
using 1 line:
MyStruct1 m_struct = {0} ;
In C++, I would have liked to resort to something similar (well
excluding the declaration part), using an initialization list like so:
MyClass()
:m_struct({0})
{}
Of course, this dosent work. The only way I found to initilalize a C
struct was to do the ff:
MyClass()
{
MyStruct m_struct = {0} ;
}
which compiles ok - but I can't help wondering if this is correct. It
looks like a declaration - which if it is, means that my member variable
did not get initialized. What does the C++ spec say about this ?
structs, I mean they cannot have ctors/dtors because they have C linkage
(extern "C").
For eg:
MyClass
{
//Impl
private:
MyStruct1 m_struct ;
};
//In C code, I could declare/define/initialize the m_struct variable
using 1 line:
MyStruct1 m_struct = {0} ;
In C++, I would have liked to resort to something similar (well
excluding the declaration part), using an initialization list like so:
MyClass()
:m_struct({0})
{}
Of course, this dosent work. The only way I found to initilalize a C
struct was to do the ff:
MyClass()
{
MyStruct m_struct = {0} ;
}
which compiles ok - but I can't help wondering if this is correct. It
looks like a declaration - which if it is, means that my member variable
did not get initialized. What does the C++ spec say about this ?