Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with having a reference member in C++?

Tags:

c++

While reading "C++ Coding Standards: 101 Rules, Guidelines, and Best Practices" I came across the following:

Note that using a reference or auto_ptr member is almost always wrong.

However, the text doesn't elaborate on why this should be wrong. So what is so wrong about having a class with reference members?

like image 379
lindelof Avatar asked Nov 10 '22 02:11

lindelof


1 Answers

I think the text is telling you to avoid embedding in a class anything whose existence is out of the control of that class. References and auto pointers may refer to already deleted objects.

like image 84
Claudix Avatar answered Nov 14 '22 23:11

Claudix