• Advertisement
Sign in to follow this  

having a hard time learning C++

This topic is 1713 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I come from a java background, and am honestly having the hardest time learning C++. I'm using the tutorial at learncpp.com and I find that I'm not retaining most of the information I've read. Everything seems so weird in C++ as opposed to java which I find to be very straight forward. C++ feels all jumbled and messed up, and I can't do a lot of the things I can do in Java (or haven't learned how to do it yet).

 

I feel like I have to invest a lot of time just to learn how to do something that should be really simple, such as inheritance (which I found really easy in Java).

 

I just want to get to the same level I was in Java, but this task is a lot more daunting than I originally assumed.

 

Any tips?

Share this post


Link to post
Share on other sites
Advertisement

I come from a java background, and am honestly having the hardest time learning C++. I'm using the tutorial at learncpp.com and I find that I'm not retaining most of the information I've read. Everything seems so weird in C++ as opposed to java which I find to be very straight forward. C++ feels all jumbled and messed up, and I can't do a lot of the things I can do in Java (or haven't learned how to do it yet).

 

I feel like I have to invest a lot of time just to learn how to do something that should be really simple, such as inheritance (which I found really easy in Java).

 

I just want to get to the same level I was in Java, but this task is a lot more daunting than I originally assumed.

 

Any tips?

 

I recommend Bruce Eckel's free-to-download "Thinking in C++" books. Great content, good explanations - deep enough to clarify but not enough to lose focus - and good exercises. Sure, a bit old, but all code works (I ran most examples and solved most exercises with gcc and clang) and it won't stop you from learning C++11 after you've mastered the basics - actually, it will provide you with a solid base for C++11. Read Vol. 1 and do all exercises. Worth every second you spend on it.

Share this post


Link to post
Share on other sites

I come from a java background, and am honestly having the hardest time learning C++. I'm using the tutorial at learncpp.com and I find that I'm not retaining most of the information I've read. Everything seems so weird in C++ as opposed to java which I find to be very straight forward. C++ feels all jumbled and messed up, and I can't do a lot of the things I can do in Java (or haven't learned how to do it yet).

 

I feel like I have to invest a lot of time just to learn how to do something that should be really simple, such as inheritance (which I found really easy in Java).

 

I just want to get to the same level I was in Java, but this task is a lot more daunting than I originally assumed.

 

Any tips?

 

I recommend Bruce Eckel's free-to-download "Thinking in C++" books. Great content, good explanations - deep enough to clarify but not enough to lose focus - and good exercises. Sure, a bit old, but all code works (I ran most examples and solved most exercises with gcc and clang) and it won't stop you from learning C++11 after you've mastered the basics - actually, it will provide you with a solid base for C++11. Read Vol. 1 and do all exercises. Worth every second you spend on it.

+1

I also came from a java background and  found it easy learning from that book

If you aren't already, use an ide like code::blocks. It will make your life easier

Share this post


Link to post
Share on other sites

Check out thenewboston c++ tutorial on youtube. They are very clear for beginners

 

http://thenewboston.org/list.php?cat=16

Please don't use this as your only source to learn C++ from as he leaves out information in his tutorials especially around the inheritance, virtual functions and polymorphism section.

Share this post


Link to post
Share on other sites

Any tips?

 

Do projects instead of just coding aimlessly. That will work.

 

"C++ feels all jumbled and messed up"
 

Maybe it feels that way but its not:)

Share this post


Link to post
Share on other sites

Please don't use this [thenewboston] as your only source to learn C++ from as he leaves out information in his tutorials especially around the inheritance, virtual functions and polymorphism section.

He doesn't just leave out information, he's also outright incorrect at points.  A lot of beginners seem to find TheNewBoston's videos valuable and easy to follow, and so I've always taken the stance that I won't outright recommend not using them -- but you should definitely be using other resources as well to correct any mistakes and fill in the blanks.

 

 

Like the above, I would strongly recommend more practice -- things will stick with you once you're actually using them.  It can be frustrating moving from an easier language to something lower-level where you aren't able to do the same things as easily, but you'll get it if you persist. smile.png

Share this post


Link to post
Share on other sites

I'm surprised nobody mentioned The Famous C++ FAQ - http://www.parashift.com/c++-faq/

 

Over the years, I fond it to be an invaluable resource to refresh the knowledge (before an Interview) and connect all dots - with only a few lines/paragraphs of text (instead of 10 pages in some book).

 

Once you can answer all those questions, it will mean that you understand the design and implementation of the language, and you will be a master of C++  - of course, for that level of knowledge, you will need to go through many books - Design Patterns, STL, Template Metaprogramming, ...

 

I'm not sure I'd recommend Bruce Eckel's Thinking in C++ at this early stage, though. It's a pretty heavy read that is best to enjoy once you have a basic grasp on the most basic low-level C++ concepts like pointers, virtual methods and templates (and no, Java exp. doesn't really count here).

 

And that's before we even touch the subject of C++11....

Share this post


Link to post
Share on other sites

I mostly used Cplusplus.com to learn C++ but I could already program at the time and was only interested in learning the syntax. Good thing about that site is it shows the way C++11 does things as well. I would start learning the basics of C++11 as well because "auto" (C# "var") and ranged for will make most of the crazy STL iterator stuff go away for you and it will seem more like C# or Java.

 

 

I'm surprised nobody mentioned The Famous C++ FAQ - http://www.parashift.com/c++-faq/

 

Over the years, I fond it to be an invaluable resource to refresh the knowledge (before an Interview) and connect all dots - with only a few lines/paragraphs of text (instead of 10 pages in some book).

 

Once you can answer all those questions, it will mean that you understand the design and implementation of the language, and you will be a master of C++  - of course, for that level of knowledge, you will need to go through many books - Design Patterns, STL, Template Metaprogramming, ...

 

I'm not sure I'd recommend Bruce Eckel's Thinking in C++ at this early stage, though. It's a pretty heavy read that is best to enjoy once you have a basic grasp on the most basic low-level C++ concepts like pointers, virtual methods and templates (and no, Java exp. doesn't really count here).

 

And that's before we even touch the subject of C++11....

 

As I mentioned before there are a few things in C++11 that make the langauge easier to use for people who are coming from higher abstraction layers, sadly not all the features are implemented in all compilers yet. GCC is currently mostly there and so is Clang I think. But the ranged for(foreach) and auto keywords are definitely something C# and Java programmer will understand and be able to harness.

Edited by NightCreature83

Share this post


Link to post
Share on other sites

Well, we've had the basic for_each for about a decade (perhaps slightly less) in C++, available from <algorithm>

That's probably an area I'd recommend anyone [coming from a managed language] to start.

 

I'm still not convinced C++11 makes things much easier for people coming from managed languages. Half of those concepts must seem pretty alien...

 

I still think one has to learn C++ bottom up - you do need to tear a bunch of hair here and there to truly appreciate things like Smart Pointers, STL data structures (over regular arrays), STL algorithms, ....

 

It's usually only then that the design choices of the language designers click

Share this post


Link to post
Share on other sites

Most of the stuff in algorithm sadly require you to know about functors and function pointers to make them work effectively, using a lambda on those is actually a lot nicer then either of the previous one (see http://nwcpp.org/static/talks/2011/lambda.pdf).

 

But we are getting off topic here, the only way as mentioned before to really learn C++ is by shooting yourself in the foot repeatedly and learning from those mistakes, and C++ makes it easy to shoot yourself in the foot. So as a beginner I would stay away from anything that is intermediate level at the beginning and write code that just runs on the stack to begin with as you would in Java and C#. The heap is not hard to manage but object life time will come in to play when using the heap lots, as you need to manage the allocation on the heap as well as the deallocation of your objects in it.

Share this post


Link to post
Share on other sites

I'm using the tutorial ... and I find that I'm not retaining most of the information I've read.

 

I think that's your problem right there.

IMO, attempting to learn C++ using a tutorial is a 100%-sure recipe for confusion and failure.

Given that you're also going to have to un-learn what you've seen in most on-line tutorials on C++ (they usually follow egregiously bad coding practices), it's worse than a waste of time, it's a negative use of time.

 

Instead, I'd recommend you work through one of the books suggested here: http://isocpp.org/get-started

Note that "work through" is meant in the active sense -- in particular, as others mentioned, you must do the coding exercises, simply reading the book is not sufficient.

 

See also:

http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list

 

More people in your situation (with relevant advice):

http://stackoverflow.com/questions/403431/switching-from-java-to-c-whats-the-easy-way

http://www.reddit.com/r/gamedev/comments/1b62qt/moving_from_c_to_c_having_already_knowledge_of_oo/

http://www.reddit.com/r/cpp/comments/zpigl/refreshing_c/
http://www.reddit.com/r/cpp/comments/ks4yd/learning_c_as_a_java_user_starting_with_the_snake/c2muazn
http://www.reddit.com/r/cpp/comments/hxc1f/can_anyone_suggest_a_good_book_to_help_with_the/
http://www.reddit.com/r/cpp/comments/12f3bl/which_book_is_best_to_learn_c/
 

Edited by Matt-D

Share this post


Link to post
Share on other sites

I come from a java background, and am honestly having the hardest time learning C++. I'm using the tutorial at learncpp.com and I find that I'm not retaining most of the information I've read. Everything seems so weird in C++ as opposed to java which I find to be very straight forward. C++ feels all jumbled and messed up, and I can't do a lot of the things I can do in Java (or haven't learned how to do it yet).

What kinds of things can you not do?

I feel like I have to invest a lot of time just to learn how to do something that should be really simple, such as inheritance (which I found really easy in Java).

There is nothing simple about inheritance. But still, I don't think C++ makes it particularly hard.

I just want to get to the same level I was in Java, but this task is a lot more daunting than I originally assumed.

Any tips?

C++ is a confusing language. I failed to learn it on my own a couple of times. On my third attempt I was actually using it at work, where we have a local guru, and I succeeded. Don't get me wrong: After 11 years using C++ daily, there are still dark corners of the language that I don't understand, but I know to stay away from them. ;)

Anyway, as others have said, you need to do a lot of coding in C++ to get good at it. Feel free to post in these forums with more specific questions about difficulties you may encounter. Edited by Álvaro

Share this post


Link to post
Share on other sites

The good thing about C++ [from the learning standpoint] is that it is incredibly unforgiving [especially compared to a managed runtime like C# / Java] and makes it very easy to mess things up.

 

Which is a good thing, since the long-term memory and coding reflexes are best initialized by spending hours in a debugger / stackoverflow / msdn and not by a single short exercise that works the first time you try it out.

 

 

As a kid, did you listen to your parents to not touch the Hot Iron on the Ironing board or did you rather learn by burning your hand smile.png  ?

Share this post


Link to post
Share on other sites

I'm surprised nobody mentioned The Famous C++ FAQ - http://www.parashift.com/c++-faq/

 

Over the years, I fond it to be an invaluable resource to refresh the knowledge (before an Interview) and connect all dots - with only a few lines/paragraphs of text (instead of 10 pages in some book).

 

Once you can answer all those questions, it will mean that you understand the design and implementation of the language, and you will be a master of C++  - of course, for that level of knowledge, you will need to go through many books - Design Patterns, STL, Template Metaprogramming, ...

 

I'm not sure I'd recommend Bruce Eckel's Thinking in C++ at this early stage, though. It's a pretty heavy read that is best to enjoy once you have a basic grasp on the most basic low-level C++ concepts like pointers, virtual methods and templates (and no, Java exp. doesn't really count here).

 

And that's before we even touch the subject of C++11....

http://yosefk.com/c++fqa/

 

My tip: Leave C++ and never look back. It's pure evil.

Share this post


Link to post
Share on other sites
&nbsp;

I recommend Bruce Eckel's free-to-download "Thinking in C++" books. Great content, good explanations - deep enough to clarify but not enough to lose focus - and good exercises. Sure, a bit old, but all code works (I ran most examples and solved most exercises with gcc and clang) and it won't stop you from learning C++11 after you've mastered the basics - actually, it will provide you with a solid base for C++11. Read Vol. 1 and do all exercises. Worth every second you spend on it.

&nbsp;

It WAS a good book, but C++ has progressed and now it is a good book about an obsolete language that shouldn't be used. There are, of course, common roots, but why learn (and unlearn) old and unpleasant techniques along with the complex enough current state of C++?

A random example of how modern C++ has removed syntactic and conceptual cruft:
http://herbsutter.com/2013/05/09/gotw-1-solution/

Share this post


Link to post
Share on other sites

I think C++ is a great language. You can do so many neat memory management tricks with C++ than with Java or .NET. It is also a true work horse if you get your code right. For me, understanding how memory layout and memory management works in C++, helped a lot learning C++ language. I think it is also quite cool that when you work with C++ you'll get to know how memory management works in OS and you surely get know difference between stack and heap memory and what are pros and cons per each.

 

When you learn all these, moving then to some more higher level language is quite easy. It is good to know, that even if you are using Java or .NET same C/C++ things happens under the hood. I think it is kind of language what gives to you quite a lot of. It takes time to learn, but I think it's totally worth of.

 

Altough I hate header file comments when working with std-library. It's so cryptic, I'll have to say that. Fortunately in cplusplus.com std-library is documented quite well.

 

This is not perhaps best example, but I found it really cool that how easy it is to corrupt stack with C standard methods and run method from the stack with buffer overflow attack. That kind of things just open your eyes. It was a practice what we did in school.

Share this post


Link to post
Share on other sites
Actually C++ is an abstraction over the memory management system of the OS, which itself is an abstraction over the actual hardware. That's the first time I've heard the fragility and insecurity of C++ as a plus point!


To the OP, if you got the language basics down, try the tutorial in my sig. It covers a lot of C++ concepts, but with real non trivial code.

This is why I hate most book samples, it's hard to grok something when all the examples are so abstract.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement