devxlogo

Prefer References Over Pointers

Prefer References Over Pointers

Even experienced C++ programmers who have prior experience with C tend to use pointers excessively whereas references may be a better choice. Pointers may result in bugs like the following:

 bool isValid( const Date *pDate);void f(){	Date *p = new Date(); //default: current date	//...many lines of code	delete p;		//p is now a

devx-admin

Share the Post: