Error value initialization of which has reference type




















List initialization. Aggregate initialization. Static initialization. Zero initialization. Constant initialization. I thought that because of the second constructor that the member variable should be a reference and maybe my second constructor should use a reference parameter too - but then I am a little confused.

Ben: I'm confused by your description. Is the Bar object supposed to be linked to the Foo passed in to the one-argument constructor, such that it sees future changes to that Foo instance?

If so, you'll need a reference parameter in the constructor, and a reference member variable. For the zero-argument case where you want a new Foo instance, you need a non-reference member variable, which the reference can bind to. Luchian's answer shows this in code. BenVoigt thanks for your help, I think I figured this out. I am coming from a C background where class members start as references and need to be initialized.

I have also been reading about the automatic copy constructor. Luchian Grigore Luchian Grigore k 60 60 gold badges silver badges bronze badges. The member order doesn't actually matter -- binding references is one of the few things that's expressly permitted to do with a location that will hold an object in the future but doesn't yet.

Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. You can make a copy of the object or add the const to your attribute. Python Javascript Linux Cheat sheet Contact.

Constant initialization. Value categories. Order of evaluation. Operator precedence. Alternative representations. Boolean - Integer - Floating-point. Implicit conversions - Explicit conversions. Class declaration. Access specifiers. Virtual function.

Default constructor. Copy constructor. Copy assignment. Class template. Function template. Template specialization.



0コメント

  • 1000 / 1000