bug patten in C++

A

Andy

Hi,

I am still learing C++. What are the most common mistakes that people
often made in C++? Mistach of new/delete should be one. How about
others?

Andy
 
D

davidrubin

using = instead of ==
passing a value when they should be passing an address
not implementing deep copy in copy ctors and operator=
not checking whether 'this == &rhs' in operator=
/ david
 
M

Mike Wahler

Andy said:
Hi,

I am still learing C++. What are the most common mistakes that people
often made in C++? Mistach of new/delete should be one. How about
others?

Spelling and grammar. Work on them. Seriously.
They're far more important when dealing with
computer languages than with human languages.

Another big mistake I see often with beginners is
trying to write code too soon (not having read
enough) and writing too much code all at once.
I.e. trying to run before learning to walk.

Another one I've seen too many times is being too
cheap to purchase quality textbooks (or too lazy
to find a library from which to borrow them), and
trying to rely solely on the internet for information;
this very often results in acceptance of incorrect
information as correct, and much wasted time
and effort.

BTW have you read the C++ FAQ? If not, do so. Do it
now. Go directly to the FAQ, do not pass GO, do
not collect $200. http://www.parashift.com/c++-faq-lite/
There will be a quiz on Monday (just kidding :) )

-Mike
 
R

Richard Herring

Andy said:
Hi,

I am still learing C++. What are the most common mistakes that people
often made in C++? Mistach of new/delete should be one. How about
others?
Confusion between new[]/new, delete[]/delete.

*Using* new[]/delete[] at all ;-) In most cases std::vector is what's
really needed.

Using delete, instead of letting a smart pointer take care of it.

Unnecessary use of new (particularly prevalent in ex-Java programmers)

For the rest, just look how many postings here are answered with a
reference to the FAQ.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,201
Messages
2,571,048
Members
47,651
Latest member
VeraPiw932

Latest Threads

Top