Archived

This topic is now archived and is closed to further replies.

Emonious

Ouch C++ can be painful!

Recommended Posts

Well, I''m a novice programmer and am now learning C++ and have run into a few things that are kind of unclear to me. I never really dealt with classes since I mainly worked with C, so it is still a new concept for me, and getting it down slowly. Classes IN Classes is hard as hell for me as well. Now I am on the chapter in my lil book where it is going over pointer use in method calls in classes. Pointers, I had down to a decent degree before, but now that they are being mixed in with classes and their method calls I''m getting confused to the purpose of even having an object in heap memory. Any pro''s with C++ know the reasons this is done, and to not simple create it in the stack? I get the feeling this a question with an obvious answer to someone with experience. So anyone who knows the deal behind the use of pointers with classes, your help would be greatly appreciated. Maybe the problem is I just don''t understand classes well... Dunno Thanks.

Share this post


Link to post
Share on other sites
quote:
Original post by Emonious
Now I am on the chapter in my lil book where it is going over pointer use in method calls in classes. Pointers, I had down to a decent degree before, but now that they are being mixed in with classes and their method calls I''m getting confused to the purpose of even having an object in heap memory. Any pro''s with C++ know the reasons this is done, and to not simple create it in the stack?
For the exact same reason you would do it in C with a struct or whatever. Of course, anything created on the stack is destroyed when you exit the scope, and there are plenty of situations where you don''t want that to happen.

Share this post


Link to post
Share on other sites
Don''t worry about it too much for now. Once you start studying things like linked lists and dynamic arrays, pointers will make perfect sense.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
Alrighty. That chapter is coming up in a few weeks at my reading speed.

I do wonder though, do any of you know of any good sites that explain classes and related material well? The book didn''t do a very good job.

Share this post


Link to post
Share on other sites
Search for articles on Google, surely you''ll find thousands of them. What''s your book? I myself learned C++ from Deitel and Straustrup, Deitel is relatively easy and Straustrup is relatively professional and complete. Make sure that you understand what STRUCT in C is in order to get the classes, and afterall as my own experience shows, you''ll understand all that stuff when writing on raw C you''ll natively need it, like functions in structures, inherited structures and so on. Until you don''t need it for your problem, you probably will have difficulties understanding it. Afterall all the classes, polymorphism, templates, inheritance and other ''tough'' things aren''t meant to make the language more complicated, but to make the programming more comfortable. My advice is - invent basic/moderate problems for yourself and write solutions. Do it for some time [two or three weeks], then after getting/USING whole C stuff re-read your C++ book. You''ll find C++ a gift from the Heaven Good luck.

I hate you.

Share this post


Link to post
Share on other sites