Re: printing in C++
On Saturday, 16 March 2013 22:35:44 UTC, =D6=F6 Tiib wrote:
On Sunday, 17 March 2013 00:17:48 UTC+2, James Kanze wrote:
On Saturday, March 16, 2013 4:56:16 PM UTC, =D6=F6 Tiib wrote:
I
have strong belief that after C++11 we really do not need to
use any naked pointers in everyday programming.
Most pointers in well written C++ are for navigation, and should
be raw pointers.
Why? For navigation there are usually iterators. While standard allows
raw pointers as iterators all modern implementations use special
classes that are as efficient and lot safer.
How can you navigate using iterators. The target objects aren't
necessarily in any particular sequence.
Smart pointers have they uses, but they still
correspond to exceptional cases, rather than the usual case.
Pointer has several usages: container (array), iterator of container,
optional object and for polymorphic object. It is best alternative
for none of the tasks.
Pointers are mainly used for navigation (or not used at all).
There are exceptions: polymorphic objects, and iterating over
C style arrays, and optional arguments (or unsuccessful return
values) are good examples. In the case of temporary polymorphic
objects, smart pointers often are appropriate. But certainly
*not* in the other two cases. (And short lived polymorphic
objects aren't that common.)
--
James