CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 33
  1. #1
    Join Date
    Jan 2010
    Posts
    75

    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.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Learn C++ from C

    Quote Originally Posted by RipRage View Post
    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

  3. #3
    Join Date
    Aug 2009
    Posts
    440

    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++.

  4. #4
    Join Date
    Mar 2004
    Location
    Central Florida
    Posts
    293

    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Learn C++ from C

    Quote 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++.

    Quote 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++.

    Quote 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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  6. #6
    Join Date
    Mar 2004
    Location
    Central Florida
    Posts
    293

    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.

  7. #7
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Learn C++ from C

    Quote 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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  8. #8
    Join Date
    Mar 2004
    Location
    Central Florida
    Posts
    293

    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.

  9. #9
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Learn C++ from C

    Quote Originally Posted by mlgoff View Post
    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?
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  10. #10
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Learn C++ from C

    Quote Originally Posted by mlgoff View Post
    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.

  11. #11
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Learn C++ from C

    Quote Originally Posted by mlgoff View Post
    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.

  12. #12
    Join Date
    Mar 2004
    Location
    Central Florida
    Posts
    293

    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.

  13. #13
    Join Date
    Jan 2010
    Posts
    75

    Re: Learn C++ from C

    Thank you for your replies experts.
    Quote 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.

    Quote 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.

  14. #14
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Learn C++ from C

    Quote Originally Posted by mlgoff View Post
    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.

  15. #15
    Join Date
    Jan 2010
    Posts
    75

    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?

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured