|
-
March 19th, 2012, 09:37 AM
#1
Learn C++ from C
Hi Experts,
Just a quick one, can anyone recommend any decent books / sites that can teach you C++ from someone who has a fairly good knowledge of C and the WinAPI.
Main things i am interested in mastering are the object oriented features and concepts.
Thanks in advance.
-
March 19th, 2012, 09:59 AM
#2
Re: Learn C++ from C
 Originally Posted by RipRage
Hi Experts,
Just a quick one, can anyone recommend any decent books / sites that can teach you C++ from someone who has a fairly good knowledge of C and the WinAPI.
Main things i am interested in mastering are the object oriented features and concepts.
Thanks in advance.
Accelerated C++ by Koenig & Moo. That book is geared to programmers who know another language that want to learn C++.
Also, realize that C++ is a different language than C, and you may/will need to unlearn a lot of things you did in 'C'. This means that a lot of things you did when programming in 'C' are not necessary, and in some cases, invalid in a C++ program.
Regards,
Paul McKenzie
-
March 19th, 2012, 02:34 PM
#3
Re: Learn C++ from C
I just want to add my $0.02. I learned C++ and then got an internship at a company that uses both C and C++. Yes, they are similar in some aspects, but they really are two different languages. So, I would keep that in mind when learning C++.
-
March 20th, 2012, 12:30 PM
#4
Re: Learn C++ from C
As someone who learned C long before C++, I can atest that C++ is a superset of C. They are not different languages.
That said, C follows a Procedural approach to programming, whereas C++ was designed around Object Oriented Programming. That is the real difference and the reason so many people believe they are different languages.
I have converted hundreds of thousands of lines of C code to C++. I can tell you that while there are a few things in the C99 Standard that are incompatible with the C++ Standards, there isn't anything in C that is invalid in C++.
"Effective teaching is the essence of leadership..."
"There is no substitute for a carefully thought-out design."
If you have found this post to be useful, please Rate it.
-
March 20th, 2012, 12:42 PM
#5
Re: Learn C++ from C
 Originally Posted by mlgoff
As someone who learned C long before C++, I can atest that C++ is a superset of C. They are not different languages.
That is absurd. Unless C++ is C, which is obviously not the case, they are different languages. I suggest reading Stroustrup's answer to the FAQ: Is C a subset of C++? for a more sensible way of expressing the relationship between C and C++.
 Originally Posted by mlgoff
That said, C follows a Procedural approach to programming, whereas C++ was designed around Object Oriented Programming. That is the real difference and the reason so many people believe they are different languages.
When paradigms and idioms appropriate to C and C++ differ (and this is more than just a matter of procedural versus OOP), it is indeed the case that they are different languages. Pretending that modern C++ is just an extension to C is a poor way of approaching C++.
 Originally Posted by mlgoff
I have converted hundreds of thousands of lines of C code to C++. I can tell you that while there are a few things in the C99 Standard that are incompatible with the C++ Standards, there isn't anything in C that is invalid in C++.
Indeed, as far as I know, C++98 attempts to be compatible with C89, and C++11 attempts to be compatible with C99, though with some differences. Nonetheless, a valid C program is not necessarily a valid C++ program.
Last edited by laserlight; March 20th, 2012 at 12:46 PM.
-
March 20th, 2012, 12:48 PM
#6
Re: Learn C++ from C
You might want to re-read that one yourself. Effectively (rather than mathematiucally) C is a subset of C++.
"Thus, C++ is as much a superset of ANSI C as ANSI C is a superset of K&R C and much as ISO C++ is a superset of C++ as it existed in 1985. "
"Effective teaching is the essence of leadership..."
"There is no substitute for a carefully thought-out design."
If you have found this post to be useful, please Rate it.
-
March 20th, 2012, 12:50 PM
#7
Re: Learn C++ from C
 Originally Posted by mlgoff
Effectively (rather than mathematiucally) C is a subset of C++.
More precisely, C is effectively a proper subset of C++, and the differences imply different paradigms and idioms that are appropriate to each. Therefore, C++ is a different programming language from C.
-
March 20th, 2012, 12:52 PM
#8
Re: Learn C++ from C
Stated that way, I agree.
"Effective teaching is the essence of leadership..."
"There is no substitute for a carefully thought-out design."
If you have found this post to be useful, please Rate it.
-
March 20th, 2012, 12:55 PM
#9
Re: Learn C++ from C
 Originally Posted by mlgoff
I have converted hundreds of thousands of lines of C code to C++. I can tell you that while there are a few things in the C99 Standard that are incompatible with the C++ Standards, there isn't anything in C that is invalid in C++.
So in other words the effort that gave you all the experience was just to compile the code as C++ instead of C?
-
March 20th, 2012, 01:08 PM
#10
Re: Learn C++ from C
 Originally Posted by mlgoff
I have converted hundreds of thousands of lines of C code to C++. I can tell you that while there are a few things in the C99 Standard that are incompatible with the C++ Standards, there isn't anything in C that is invalid in C++.
When I state "invalid", I'm meaning using 'C' constructs within a C++ program without any regard for those big differences in the two languages.
How many times has stuff like what you see below been posted here? Too many times.
Code:
#include <stdlib.h>
#include <string>
struct S
{
std::string s;
};
int main()
{
S* pS =(S*)malloc( sizeof(S) );
pS->s = "abc123";
free (pS);
}
Then the 'C' programmer scratches their head in amazement that the program crashes or works sometimes and not other times.
How about examples that look like this, which again, seems to be posted on a bi-weekly basis here:
Code:
#include <string>
#include <stdio.h>
struct S
{
std::string s;
};
int main()
{
S pS;
pS.s = "abc123abc123abc123";
FILE *f = fopen("whatever.bin", "wb");
if ( f )
{
fwrite( &pS, 1, sizeof(S), f );
fclose ( f );
}
}
The above is what a C programmer habitually does when writing to a file in binary mode -- OK for 'C', not so much for C++. This won't crash, but the file will more than likely contain junk, not the string they expected to have.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; March 20th, 2012 at 01:12 PM.
-
March 20th, 2012, 01:23 PM
#11
Re: Learn C++ from C
 Originally Posted by mlgoff
there isn't anything in C that is invalid in C++.
There are a few things. Assuming an implicit return type of int isn't valid in C++ and neither is assigning a (void*) return from malloc to another pointer type without a cast.
-
March 20th, 2012, 02:47 PM
#12
Re: Learn C++ from C
So in other words the effort that gave you all the experience was just to compile the code as C++ instead of C?
No. A lot of debugging was involved. But it was more due to non-standard compilers/language implementations than to differences between C and C++.
When I state "invalid", I'm meaning using 'C' constructs within a C++ program without any regard for those big differences in the two languages.
Granted.
There are a few things. Assuming an implicit return type of int isn't valid in C++ and neither is assigning a (void*) return from malloc to another pointer type without a cast.
I wasn't thinking about those things. I was thinking about the C Standard Library and general syntax.
Obviously there are differences. But from the stand-point of learning C++, the biggest obstical is not syntax, it is the difference between Procedural and OOP paradygms. RipRage's knowledge of C should serve him well.
BTW- I didn't know Stroustrup had a FAQ. I've really been enjoying it. I also understand Paul's initial assertion that they are separate languages. Thank you.
"Effective teaching is the essence of leadership..."
"There is no substitute for a carefully thought-out design."
If you have found this post to be useful, please Rate it.
-
March 20th, 2012, 03:57 PM
#13
Re: Learn C++ from C
Thank you for your replies experts.
 Originally Posted by Paul McKenzie
Accelerated C++ by Koenig & Moo. That book is geared to programmers who know another language that want to learn C++.
Thank you for this Paul, i have jumped straight into this.
 Originally Posted by mlgoff
But from the stand-point of learning C++, the biggest obstical is not syntax, it is the difference between Procedural and OOP paradigms
Yes, this will be the hardest part for me.
Thanks again all.
-
March 21st, 2012, 10:37 AM
#14
Re: Learn C++ from C
 Originally Posted by mlgoff
Obviously there are differences. But from the stand-point of learning C++, the biggest obstical is not syntax, it is the difference between Procedural and OOP paradygms. RipRage's knowledge of C should serve him well.
OOP is only one way that C++ can be used. I actually think that generic programming using templates is a bigger difference in some ways.
Also critical, though related, is learning to use RAII techniques, especially the STL. You can write OOP code in C++, but if it uses C style memory management internally, you are wasting your valuable time.
-
March 28th, 2012, 11:10 AM
#15
Re: Learn C++ from C
Hi Experts;
I also forgot to mention, what is the best way to use the C++ STL with the windows API. Since the API is built using C, i would like to know if it possible to pass std::wstring and std::vectors etc to parameters that take for example PTSTR, LPWTSR etc for some of the common functions contained within the API,
Or since this is C++, shall i stop using the API and start learning MFC ?
Thanks in advance?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|