In article <4d**********************************@b2g2000prf.g ooglegroups.com>,
<da********@gmail.comwrote:
>Hi folks........
I want to learn C++,I already know C Language,will that help me.I
require it for my job,How many days will it take to learn?
I'd estimate about 3650 days, give or take a few thousands :-(
I second most of the comments given by other posters including some very
good recommended books.
However, you say you need it for your job. IMO, it is possible and
valuable to use C++ simply as a better C.
Some possible steps:
1- Use a C++ compiler to compile all your C files. C++ compilers are
generally more fussy and issue more warnings or even errors on dodgy
practices in particular unsafe pointer practices. Fixed the errors
and warnings where possible. This should improve your code.
2- Learn about const correctness and start using it in your
interfaces. This will be needed once you replace all these pointers
by std::string, std:vector, call by reference, etc. This also leads
to better code.
3- Stop using NULL terminated buffer of characters as "string" data.
Switch to std::string. Much better overall. (and remove strcmp,
strtok, strlen, etc. from your code at the same time)
4- Stop using C-arrays. std::vector is better in the huge majority of
cases.
5- Switch to using the C++ standard library (the STL) as much as
possible.
6- Stop using pointers all the time. References plus the STL remove
the need of pointers in a lot of places and lead to safer code.
7- Initialise all your variables, declare your variables at the point
of use rather than at the start of functions, shorten your functions,
none of that impossible in C but far too often neglected.
By then, you won't have proper C++ code but you should certainly have
cleaner, safer code that is faster to develop.
You can then start working on classes. Often the first thing
introduced in a C++ book but IMO, if you have to adapt quickly on the
job or if you have a significant C code base that is not object
oriented and want to bring in some of the C++ productivity benefits,
C plus C++ STL is a good way to start.
So now, look at where you have a family of functions acting on similar
data. Particularly, where you have
struct TheStruct { ...};
int foo( TheStruct * ts, ...);
int bar( TheStruct * ts, ...);
These are classes.
On the side, when working on new stuff, try to write it in "proper"
C++. Gradually switch to using all the good concepts presented in
these good books that were recommended. Don't ignore exceptions.
Too many C programmers switching to C find exception safety too
complicated and decide to stick with the awkward return error code and
ignore exceptions. C++ has exceptions, the STL has exceptions, even
if you try to ignore them, they are still there. Learn and embrace
them, that will be more productive in the longer term.
Anyway, hope this help and have fun
Yannick