Quote:
Originally Posted by kerowo
You do you probably just call it a reference instead...
True and in C++ there is
The auto keyword where the compiler deduces the type I.E. not statically typed.
Using "smart" pointer mechanisms prevent inevitable "memory leaks" that happen when using dynamic memory allocation.
I am not beating the drum for C++ in lieu of using say something like Python, JS, C#, etc., far from it. FWIW grue's perspective is the right perspective.
However, C++ is much preferred to C in the problem domains it applies to. There are some very basic reasons why:
1 - Rogue pointer issues (trashed pointers, null pointers) are nasty and difficult to root out.
2 - Memory leaks caused by using dynamic allocation are also nasty problems to resolve.
3 - STL is much better in producing reliable and secure code than the standard C library.
4 - Encapsulation is easy in C++. Encapsulation in C is a joke.
5 - Polymorphism in design is relatively easy to in C++. In C, not so much.
6 - Templates which I guess you could say is part of encapsulation but there far more useful than that. Templates make C++ "Turing Complete" at compile time which brings about a lot of potential for weeding at defects at compile time as opposed to weeding them out at run time.