In this specific case, is there a difference between using a member initializer list and assigning values in a constructor?

You need to use initialization list to initialize constant members,references and base class When you need to initialize constant member, references and pass parameters to base class constructors, as mentioned in comments, you need to use initialization list. struct aa { int i; const int ci; // constant member aa() : i(0) {} // will … Read more

What does a colon following a C++ constructor name do? [duplicate]

This is a member initializer list, and is part of the constructor’s implementation. The constructor’s signature is: MyClass(); This means that the constructor can be called with no parameters. This makes it a default constructor, i.e., one which will be called by default when you write MyClass someObject;. The part : m_classID(-1), m_userdata(0) is called … Read more

Automatically initialize instance variables?

You can use a decorator: from functools import wraps import inspect def initializer(func): “”” Automatically assigns the parameters. >>> class process: … @initializer … def __init__(self, cmd, reachable=False, user=”root”): … pass >>> p = process(‘halt’, True) >>> p.cmd, p.reachable, p.user (‘halt’, True, ‘root’) “”” names, varargs, keywords, defaults = inspect.getargspec(func) @wraps(func) def wrapper(self, *args, **kargs): … Read more

Initialize parent’s protected members with initialization list (C++)

It is not possible in the way you describe. You’ll have to add a constructor (could be protected) to the base class to forward it along. Something like: class Parent { protected: Parent( const std::string& something ) : something( something ) {} std::string something; } class Child : public Parent { private: Child() : Parent(“Hello, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)