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

Started by
13 comments, last by Spoonbender 18 years, 8 months ago
Okay. I'm a C guy. I only started working with C++ about 8 months ago, after using C for almost 10 yesrs. Now I believed that there was NO NEED for anything object orientatied, or any other language, until I started using C++ or should i say learning it.

Now I beleive that it is so much more powerful. Inheritence on it's own is just so wonderful..with all the concepts of polymorhism..virtual functions...amazing. And then ou get onto templates.....how fantsistic. Generic programing, and that just the tip of everyting.

I'm not too sure if Java, or C# give you anthying as powerful, but the "subelties" make the language. Please just try them...just once and then again and then somethiung else will crop up and then you'll be hooked.

It might seem like "black magic"...just like TCP/IP or E=mc pow(2) did one time. but it's worth the effort.

Just my opinion.

Gary.Goodbye, and thanks for all the fish.
Advertisement
Quote:Original post by swinchen
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?)


[edit: I complete misread the statement.

No, that's not true. The variable pointed to can be changed, not the pointer itself. I went to all the trouble of doodling this example, so I'm leaving the post, and editing the previous. :]

foo.cc
#include <iostream>#include <sstream>#include <string>using namespace std;void    square(long     x){        x=x*x;}void    squareptr(long          *x){        *x=(*x)*(*x);}void    swapptrs(long   **a, long       **b){        long    *c=(*a);        (*a)=(*b);        (*b)=c;}int     main(){long    n,p;long    *ptrn, *ptrp;n=42;p=6;ptrp=&p;ptrn=&n;cout << "n before square: " << n << "\n";square(n);cout << "n after square: " << n << "\n";cout << "p before squareptr: " << p << "\n";squareptr(&p);cout << "p after squareptr: " << p << "\n";cout << "n: " << n << "   p: " << p << "\n";cout << "&n: " << &n << "   &p:" << &p << "\n";cout << "ptr n: " << ptrn << "   ptr p: " << ptrp << "\n";cout << "*ptr n: " << *ptrn << "   *ptr p: " << *ptrp << "\n";cout << "\nSWAP!\n\n";swapptrs(&ptrn, &ptrp);cout << "n: " << n << "   p: " << p << "\n";cout << "&n: " << &n << "   &p:" << &p << "\n";cout << "ptr n: " << ptrn << "   ptr p: " << ptrp << "\n";cout << "*ptr n: " << *ptrn << "   *ptr p: " << *ptrp << "\n";cout << "\n";}


results
n before square: 42n after square: 42p before squareptr: 6p after squareptr: 36n: 42   p: 36&n: 0xbfbff714   &p:0xbfbff710ptr n: 0xbfbff714   ptr p: 0xbfbff710*ptr n: 42   *ptr p: 36SWAP!n: 42   p: 36&n: 0xbfbff714   &p:0xbfbff710ptr n: 0xbfbff710   ptr p: 0xbfbff714*ptr n: 36   *ptr p: 42
Check out my post here.

Well, let me recommend a less ass ramming book. Since I started using C++, i have always like C++ books from Dietel & Dietel. They write books for students so its designed to be self taught. I used taht book from freshman to graduate school. Its has good examples and talks about each line of code. I would start there.
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.

What makes you think there is a difference? [lol]
No, seriously, the reason he tells you about the subtleties of the language is because you need to know about the subtleties of the language. How are you ever going to be able to use the language, if you don't know *exactly* what it does, and what your code means?

So a few suggestions:
1: Read about the said subtleties, but don't bother to understand all of it perfectly. Just make sure you know about it, so that when you encounter it in your programs, you'll be able to say "I read something about this. I think I'll go look it up".
2: Start with an easier language.

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.

I'm not dumb, I just don't understand, you mean? [wink]
No, I know what you mean, and most people when starting out, are wondering why they're always told to do completely irrelevant and pointless exercises.
I know I did, and almost everyone else I've talked to, or tried to teach programming to, have asked the same questions. "Why am I learning to write silly text-based programs that save a phonebook to a file, or add numbers together at the user's request? What does that have to do with anything?"

But it does have everything to do with learning programming. You'll understand that too (once you get to the point where you no longer need to wrestle with it, and so by then it's a bit late)

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

Would you? How do you know you'd cover the entire language then?
No, I think you should stick to using books. Of course, you don't have to do every exercise in every book, and understand every single word. But you have to make damn sure you've gone through *everything* in the book, so that you at least know about it, even if you can't remember everything, or are having difficulty understanding how some of it is useful.
You still need to know which features the language has, so you can recognize them later on, or at least, realize when you run into a problem where they'll be useful.

That's the main reason why I don't trust online tutorials alone. They tend to be a lot more patchy, teaching specific things very well, but skipping over a lot of other things. And if you were to just decide on your own what you need to learn, then the result would be much the same.

This topic is closed to new replies.

Advertisement