Is there a way to use a reference as a member variable without initialising it in the constructor?
My problem is that I don’t have the reference at hand when constructing the object.
Is there a way to use a reference as a member variable without initialising
Share
> Is there a way to use a reference as a member variable without initialising it in the constructor?No, references must be initialized in constructor initializer list
> My problem is that I don't have the reference at hand when constructing the object.I guess what you meant is you don’t have an object to refer to. In that case you have to go for a pointer and initialize it to NULL. Then later when you have the object make the pointer point to that. A reference cannot be used in this case as you cannot initialize reference to NULL