What does :className() mean in a constructor for className?

  • A+
Category:Languages

I see some code in a codebase I'm working on that looks like:

 ZfooName::ZfooName(int magoo)     : ZfooName()  {     fGoo = magoo;  } 

I'm assuming this is a C++11 feature, since it breaks in VS2012, but what does it mean?

 


This is a new feature in C++11. It's called a delegating constructor.

The constructor calls the default constructor first (the constructor that is being delegated to). After the default constructor returns, the body of the delegating constructor is executed.

See http://www.stroustrup.com/C++11FAQ.html#delegating-ctor and https://en.cppreference.com/w/cpp/language/initializer_list#Delegating_constructor for additional information.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: