Learning C++ getting stalled... better approach?

Started by
13 comments, last by Spoonbender 18 years, 7 months ago
Hello again. I've been working through the book "C++ Primer Plus" which seems to be very good but I'm now 7 chapters in and I keep hitting a wall. In this chapter and the last one, he started discussing "the subtleties" of things like pointers in functions. I'm sick to death of reading about the subtleties of the language, I want to know how to bloody use it, not how to make love to it. Can anyone suggest a less ball-busting approach to learning C++? I'm not stupid, I just can't seem to figure out what any of this stuff I've learned (from 3 books btw not just this one) has to do with anything I might actually use. Also for some bizzare reason the programming exercises in this book and the last one I tried don't "match" the material discussed in the chapter. WTH? Would I be better off setting my own "curriculum" of programming exercises and just use the books as references rather than textbooks? Hmm, that sounds like a good idea actually... Any suggestions would be greatly appreciated, thanks in advance!
Advertisement
Almost everything I know about programming has been due to trial and error. If I come across something I know nothing about, Google usually helps. The benefits: I learn the language in my own way, and I learn the stuff I need to know to make things I want to make, rather than making things to teach me how to use the language. The downfall: I'm always learning something (not that it's a bad thing). If books aren't helping you, think of something you'd like to make, then make it. Chances are it's going to be more beneficial. Just a thought...
When I learned C++ I did it from a book and then did my own sample programs on what each chapter covered. The key for me was actually using what I was learning. Reading a book is one thing but actually sittle in front of a computer and trying to get your stuff to compile and work is another.

Now the samples you do don't have to be boring. Find something small that would fit. I did stuff like screen savers and small casino type games. You could even do the games totally text based in the console so you don't have to worry about graphics.

As for the nuances of pointers it took me a while to really get inside pointers and it happened long after I had learned to code in C++. You can still do a lot with just basic pointer understanding.
In addition to experimentation, the better of the two Es, another choice would be examination. Grab the sources from a project that is perhaps similar to a problem you're working on and read through to see how they solved it. Maybe it'll offer you insight to a solution - there's been many a time that it's just clicked when I saw it all written out in code.

But you're still probably going to become most comfortable from just trying things out. Books are like storehouses; they provide you the tools and the imprinted warning labels, but nothing of how they're going to solve your particular problem. From there it's dependent on research, imagination, and the occasional bit of 3:00 AM sleep-deprived enlightenment.
I'm afraid the problems you face are not unique to you - when I started out, I was like "What's this? It makes no sense...", "I can't be bothered" etc and, truth be told, I'm still like that now to a certain degree.

But the more you learn, the easier you'll find the simpler things, and as those simple programs complete and run perfectly, you'll achieve a level of satisfaction, thus spurring you on further.

Unfortunately, though, the ins-and-outs are required when it comes to making games, especially more complicated ones with graphics. You mentioned function pointers - these save you a great deal of code in a big project, believe me.

As for your book, you're probably best following the sample code through in the book, picking up on how the author solved the problem. Once you're happy with his or her implementation, and know how to use the syntax of C++, you'll find yourself adapting the same techniques to your own applications, and that is how you will learn (well, I did it that way, anyway [lol]).

You can then build your own curriculum, like you say.

Best of luck! [smile]

ukdeveloper.
my suggestion would be to start a simple project (space shooter for example) and use what you know to start building it.

the problems you run into will be much better teachers than any book. Also. anything you learn from a book or from google, you can apply it back to your project.

the goal is not to finnish the project, but to keep adding to it and making it better. i would suggest some sort of "game", because game programming will require you to learn more diverse topics than typical programs.

hope that helps
the mountains quake, and a little mouse pops out
Quote:Original post by Theodore Fuhringer
I've been working through the book "C++ Primer Plus" which seems to be very good but I'm now 7 chapters in and I keep hitting a wall. In this chapter and the last one, he started discussing "the subtleties" of things like pointers in functions. I'm sick to death of reading about the subtleties of the language, I want to know how to bloody use it, not how to make love to it.


C++ more than any other language it seems, really does place much of its power in said subtleties. For example, said pointers in functions:

In plain english:
A variable passed to a function cannot be changed by the function.
A variable passed to a function via pointer can be changed by the function.

[note: edited for accuracy]

This is a rather important subtlety if you have a problem where you want to change a variable with a function...

Also:
A variable declared in a function (int foo;) dies at end of the function.
A variable created via pointer in a function (int *foo=new int;) does not die at the end of the function.

If you don't know that, all of your applications will leak memory until they die. Again, a rather important distinction.

Quote:

Can anyone suggest a less ball-busting approach to learning C++? I'm not stupid, I just can't seem to figure out what any of this stuff I've learned (from 3 books btw not just this one) has to do with anything I might actually use.


Don't worry, the problems will present themselves. With only a few exceptions, all of C++ is 'useful', and you will be required to use it.

Quote:
Also for some bizzare reason the programming exercises in this book and the last one I tried don't "match" the material discussed in the chapter. WTH? Would I be better off setting my own "curriculum" of programming exercises and just use the books as references rather than textbooks? Hmm, that sounds like a good idea actually...



I wouldn't. Most student made curriculums involve simple things like... a text based adventure game. Even though such a game is 'simple' it's coding is not, and will only serve to frustrate you, or distract you from learning and finishing the book. You should finish the book before trying something of any size beyond the book's exercises. Most common problems are vastly simplified by knowing some of the stuff that's in the back of your book.

[Edited by - Telastyn on August 31, 2005 3:08:09 PM]
Less ball busting? Make sure your targets are achievable, and when you think you've learned something then go apply it.

If possible work with someone in real life, there is no substitute for a decent conversation and bouncing ideas off a peers.

Get in on the ground floor for the agile style of development. Write code as if the functions and classes you need already exist, and write them as you need them. This helps prevent coding stuff that you never use.

If you want to do graphics think about using a helper library like the SDL, which has tons of examples around. Take apart other peoples stuff, fiddle, break, fix... learn by doing!
Anything posted is personal opinion which does not in anyway reflect or represent my employer. Any code and opinion is expressed “as is” and used at your own risk – it does not constitute a legal relationship of any kind.
Quote:Original post by Telastyn
A pointer to a variable passed to a function can be changed by the function.


Is that true?

A variable passed to a funtion as a pointer can be changed... the pointer itself can not though. (wouldn't you need to pass a pointer to a pointer?)
Well I am reading right now, How to Programe in C++ fourth edtion By Detiel. I have found this book to be very helpful to me already. I am only on ch 2 of this book but how the explain what each line of code does and how it realtes to c++ is extermly hopefully. As for me I read the chars and then I will make my own little prog to see if I understnad what i leanred in that char. I will make more then one prog each time trying something different to see what I can get to work and what i cant get to work. They have excriese at the end of the char, I try them But I myself find it better to learn when you take what u have just read and make it in to your own prog I thin in my own opion that it is a easyer way for me to learn. This might now be tru for everone but it helps me alot. And also the people in this community are very nice and if they have the knowegel to help you they most likely will. Well I hope that you Have good luck in c++ programing and If u want pick up the book I mentioned it is a really good book helps out alot.

This topic is closed to new replies.

Advertisement