Best alternative for old C ++ function?

C ++ has come a long way, it has many functions that can accomplish the same task in n number of ways. Which feature do you think should be avoided and indicate the best alternative for it.

How To Use SmartPointers In Places Pointers

+1


source to share


2 answers


Avoid malloc, use a new one.

Avoid memcpy, use a copy constructor.

Avoid #defines

, use const

s.

Avoid (C-style) casts

, use static_cast<C++>( style casts )

.

Avoid macros, use templates.

Avoid post-increment if you can use pre-increment.

Avoid the new ones, use collections of value types, let the collection work with memory management.



Avoid pointers to new objects, use boost::scoped_ptr

orboost::shared_ptr.

Avoid writing your own code to move collections, use <algorithm>

s

Avoid reinventing the wheel, see if boost has what you need.

Avoid "char * name" for storing strings, use std :: string.

Avoid using namespace foo

, use using foo::bar

.

Avoid "static (internal linking) declarations" and use unnamed namespaces.

+15


source


use new style styles

static_cast, const_cast, reinterpret_cast, dynamic_cast,



instead of C style styles which are no longer considered completely safe

also prefer to use STL containers for dynamically resizing arrays at runtime

+1


source







All Articles