ctor-initializer
C++: Should I initialize pointer members that are assigned to in the constructor body to NULL?
Suppose I have: // MyClass.h class MyClass { public: MyClass(); private: Something *something_; } // MyClass.cpp[详细]
2023-04-09 01:24 分类:问答What is this weird colon-member (" : ") syntax in the constructor?
Recently I\'ve seen an example like the following: #include <iostream> class Foo { public: int bar;[详细]
2023-01-30 16:27 分类:问答Initializing a member array in constructor initializer
class C { public: C() : arr({1,2,3}) //doesn\'t compile {} /* C() : arr{1,2,3} //doesn\'t compile either {}[详细]
2023-01-22 11:34 分类:问答Initializer list makes variable uninitialized?
I have a class with the only constructor like this: IntroScreen::IntroScreen(Game *game) : View(game), counter(0.0f), message(-1), continueAlpha(255),[详细]
2023-01-07 06:26 分类:问答Complex initialization of const fields
Consider a class like this one: class MyReferenceClass { public: MyReferenceClass(); const double ImportantConstant1;[详细]
2023-01-07 02:29 分类:问答Are empty initializers preferred for default initializing integral members?
I just read a comment by GMan that class A { public: A() : m_ptr() // m_ptr is implicitly initialized to NULL[详细]
2023-01-06 19:47 分类:问答Using member functions of members in the constructor initializer
I\'ve run into the following a few times with initializer lists and I\'ve never been able to explain it well.Can anyone explain why exactly the following fails (I don\'t have a compiler to catch typos[详细]
2022-12-29 07:42 分类:问答Is it standard C++ to assign a member pointer to the address of another member in the constructor initializer?
Does this 开发者_JS百科conform to the standard? class Foo { Bar m_bar; Bar * m_woo; public: Foo() : m_bar(42, 123), m_woo(&m_bar) { }[详细]
2022-12-29 07:13 分类:问答Only static and const variables can be assign to a class?
I am learning C开发者_StackOverflow++. Just curious, can only static and constant varibles be assigned a value from within the class declaration? Is this mainly why when you assign values to normal me[详细]
2022-12-28 12:01 分类:问答Throw exception from constructor initializer
What is the best way to throw exception from the constructor initializer? For example: class C { T0 t0; // can be either valid or invalid, but does not throw directly[详细]
2022-12-27 05:55 分类:问答