Thread: Effective usage of Classes

  1. #1
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094

    Effective usage of Classes

    As long as I have been programming (not very long) I have not used classes because I have yet to find effective ways to use them. Mostly because I don't know what sort of situations they would be best for. I use functions a lot in my code, since they seem to do the job fast and well.

    Well, to the point, could anyone either give examples or suggest times when they are more useful. All the examples I have seen say mammal and dog and cat and car and stuff, nothing I can relate them to. I know how to use inhertance, so that may make the examples more easy to come by.

    Thank you

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Heres a usefull class.
    Code:
    class IrcBot
    {
        public:
            IrcBot();
            void Login();
            void Process();
            void HandleRecv(const std::string &toRecv);
            void Set_Socket(const SOCKET &sock);
            bool isOper(const std::string &recvd); 
        private:
            void loadOps();
            void loadNick();
            void splitRecv(std::string &recv, std::string &whoSent, std::string &msgSent, std::string &whatSent);
            std::string nick;
            SOCKET serverSocket;
            std::vector<std::string> ops;
    };
    Woop?

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    I tend to use classes whenever I have a group of functions that seem related to each other some way. For example, say you're writing a program to manage files of some description, you are likely to have a lot of functions that read & write etc, so you may find it makes your program more readable if you encapsulate them.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structs vs. Classes, Memory Usage
    By CrazyNorman in forum Game Programming
    Replies: 2
    Last Post: 07-17-2005, 05:43 PM
  2. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  3. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM
  4. friend function and friend classes...usage question??
    By actionbasti in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2003, 10:53 PM
  5. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM