Top "Ctor-initializer" questions

Constructor initializer list.

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 {} */ private: int arr[3]; }; I believe the reason is …

c++ c++11 initializer-list ctor-initializer aggregate-initialization
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; Foo(int num): …

c++ syntax constructor c++-faq ctor-initializer
How to initialize a const field in constructor?

Imagine I have a C++ class Foo and a class Bar which has to be created with a constructor in …

c++ constructor constants ctor-initializer
What does a colon following a C++ constructor name do?

What does the colon operator (":") do in this constructor? Is it equivalent to MyClass(m_classID = -1, m_userdata = 0);? class …

c++ constructor initialization-list ctor-initializer
Does a const reference class member prolong the life of a temporary?

Why does this: #include <string> #include <iostream> using namespace std; class Sandbox { public: Sandbox(const string&…

c++ temporary ctor-initializer const-reference
Member initialization while using delegated constructor

I've started trying out the C++11 standard and i found this question which describes how to call your ctor from …

c++ gcc c++11 ctor-initializer
How can class fields be initialized?

A bit of a basic question, but I'm having difficulty tracking down a definitive answer. Are initializer lists the only …

c++ initialization 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 MyClass::MyClass() { something_ = new Something(); } Should …

c++ pointers constructor initializer-list ctor-initializer
Variables after the colon in a constructor

I am still learning C++ and trying to understand it. I was looking through some code and saw: point3(float …

c++ constructor ctor-initializer