I've just started learning C++, and I don't really understand classes. I kind of understand what they do, but when it come to actually coding it, I'm lost. Can someone explain basic classes better than the tutorials did?
I've just started learning C++, and I don't really understand classes. I kind of understand what they do, but when it come to actually coding it, I'm lost. Can someone explain basic classes better than the tutorials did?
Depends on what tutorial you used.
If you're lost , I'd suggest you a round trip through a good book thoroughly.
The tutorials found at CProgramming.com's Class Tutorial? Did you read the rest of the C++ tutorials there?
I've read everything before it. I try to understand the lesson fully before I read the next one.Originally Posted by AndrewHunter
Keep reading then. The lessons continue to expand on themselves and will most likely answer your questions about classes with regards to how they are used, what you can do with them, ect. This is a rather big topic and not something that lends itself to being answered in a thread.
Ok; What part of the following do you not understand ? (Assuming ; as you said that you understand what classes do)
Code:class human { private: string name; float age; public: human(string,int); // Ignore this now if you don't know what this is int what_is_your_age(); string what_is_your_name(); void sleep(); void eat(string food); void walk(int distance,double direction); //.. //.. void do_some_x_job(/*....*/); };
@manasij7479
Be carefule with this.....the topic is too broad for a thread. This could easily become one of those "suck the life out of you" type of threads.
Maybe...maybe not.
But I do remember myself in a similar situation a few years ago (Though books solved it...quite fast).
If he really understands the basic concepts of the language as he claims, then he wouldn't need anything else to understand how classes can be useful.
else ..there is always a(or more) moderator to close it off !
I wasn't suggesting you not help, nor is there any reason to lock the thread. Just sharing some words of advice on open ended questions such as these. Did you by chance get a chance to read through this article when it was posted a little bit ago?
Nice read... must've missed that earlier !
It also seems to me that this community is suffering from such an infestation.
(eg symptom): Even when a new OP asks an interesting question, with slight altercations about standards and prehistoric compilers, the replies(even by the knowledgeable) generally tend to be about standards and compilers, not about the problem.
Last edited by manasij7479; 08-11-2011 at 03:12 PM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
That would depend on what you mean by "an interesting question". If the question resolves to undefined behavior then there is no point in discussing it. This may initially seem wrong, but undefined behavior is exactly what it is, undefined. You might as well discuss how many snowflakes may fall on any given day.
If the question comes because the OP is using an outdated compiler, than the solution is to get a new compiler, which would avoid the question all together.
If the question arises because the OP is trying to implement C with classes, than the solution is to learn C++. This isn't harsh or rude, it simply is the correct way of doing things. As for more complex topics, sometimes a question may arise and the obvious answer is that the OP doesn't really understand what they are doing. Then in that case referring them to the appropriate tutorial or article is the better solution; since relaying something one post at a time across a thread won't actually fix the problem.
Anyway, just my 2 cents.
No, I'm not talking about those you mentioned. For example, I recently saw a thread about a problem in virtual inheritance. It did not truly matter in that case whether he used char arrays or std::strings or whether he 'misguidedly' used conio.h (I don't know what it has that makes it so popular !! ).. Using std::strings would have certainly have made the code a little nicer...but that is not the answer to all problems, nor is pointing to a tutorial despite it being clear that the OP is not completely ignorant on the topic.
Last edited by manasij7479; 08-11-2011 at 04:01 PM.
I think a rule of thumb a lot of people here follow, that might sometimes seem counter-productive, is that if you see an issue you deal with it, even if it has nothing to do with the question. I do agree that after someone has said, "I'm using char arrays because I want to use char arrays", then the matter should drop, but there is nothing wrong with indicating a best practice or letting someone know they are working from outdated material.
Not everyone appreciates that but I think most people do. I totally appreciate it if someone sees my code and points out issues I wasn't asking about (unless I think they are full of it, lol) because those might have been real problems for me at some other point.
Communities including this one contain "consensual circles". Which is to say, we don't all agree on everything, but some of us usually will about something. As distasteful as it might occasionally seem, if you want to enjoy programming, you might as well learn to deal with other programmers and their various concerns.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Nothing wrong with pointing it out. But in some cases (like the one I pointed out) is like the examiner(or say..someone proof-reading ) finding fault with your handwriting and forgetting to actually check the answer. (I remember it once happening to me some years ago!) It is nice of them to give you a suggestion to improve your handwriting but isn't it somewhat irresponsible to overlook the wrong answer ?