Like Tree1Likes

Not getting classes

This is a discussion on Not getting classes within the C++ Programming forums, part of the General Programming Boards category; I've just started learning C++, and I don't really understand classes. I kind of understand what they do, but when ...

  1. #1
    Registered User GigaRoid's Avatar
    Join Date
    Aug 2011
    Location
    Everywhere
    Posts
    23

    Not getting classes

    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?

  2. #2
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,523
    Depends on what tutorial you used.

    If you're lost , I'd suggest you a round trip through a good book thoroughly.
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by GigaRoid View Post
    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?
    The tutorials found at CProgramming.com's Class Tutorial? Did you read the rest of the C++ tutorials there?
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  4. #4
    Registered User GigaRoid's Avatar
    Join Date
    Aug 2011
    Location
    Everywhere
    Posts
    23
    Quote Originally Posted by AndrewHunter
    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.

  5. #5
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    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.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  6. #6
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,523
    Quote Originally Posted by GigaRoid View Post
    I've read everything before it. I try to understand the lesson fully before I read the next one.
    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(/*....*/);
    };
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  7. #7
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    @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.
    rags_to_riches likes this.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  8. #8
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,523
    Quote Originally Posted by AndrewHunter View Post
    @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 !
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  9. #9
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    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?
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  10. #10
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,523
    Quote Originally Posted by AndrewHunter View Post
    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 04:12 PM.
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  11. #11
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by GigaRoid View Post
    I've read everything before it. I try to understand the lesson fully before I read the next one.
    Try and ask more specific questions then.

    Hopefully you understand the point of functions. The purpose of a class is not so different. It is a way of organizing and structuring code that promotes modularity/compartmentalization.
    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

  12. #12
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by manasij7479 View Post
    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.
    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.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  13. #13
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,523
    Quote Originally Posted by AndrewHunter View Post
    That would depend on what you mean by "an interesting question" ~.....~ 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 05:01 PM.
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  14. #14
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by manasij7479 View Post
    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 the 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.
    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

  15. #15
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,523
    Quote Originally Posted by MK27 View Post
    I think a rule of thumb a lot of people here follow, that might sometimes seem counter-productive....
    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 ?
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversions between base classes and derived classes
    By tharnier in forum C++ Programming
    Replies: 14
    Last Post: 03-18-2011, 11:50 AM
  2. Classes access other classes local variables
    By parad0x13 in forum C++ Programming
    Replies: 6
    Last Post: 01-14-2010, 04:36 AM
  3. Accessing classes over classes
    By JulleH in forum C++ Programming
    Replies: 3
    Last Post: 12-24-2009, 02:15 PM
  4. Classes with Other Classes as Member Data
    By njd in forum C++ Programming
    Replies: 2
    Last Post: 09-27-2005, 10:30 AM
  5. Help accessing classes and derived classes
    By hobbes67 in forum C++ Programming
    Replies: 8
    Last Post: 07-14-2005, 03:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21