I want to have a reference data member in a class, but I do not want to initialize it in the constructor.
How could I do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That is not possible, you have to initialize reference data members inside ctor initialization list. If you really have to do something like this, use a pointer to the data member instead of reference. Initialize pointer to
NULLin ctor and then initialize it correctly whenever you want.