Thread: Class / Class Objects?

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    20

    Class / Class Objects?

    Hey folks, I could use some help on the implementation of this:
    I have a CEngine class which is called as the program engine. Functions are Start, Loop, End. Start contains the init functions, Loop is the main loop where it checks its subsystems for data and updates, and end is where it terminates connections etc.

    Please note this isnt for a game engine.

    In this start function I'd like it to do this:

    Create new class object IRCClient (IRCClient ircbot).
    Init the ircclient, and connect using a socket class to a server. (ircbot.connect(server, ip))

    In the ircclient class, how would i store the socket?

    Would this suffice?

    Code:
    #include "MySocket.h"
    
    class IRCClient
    {
    public:
      IRCClient();
      ~IRCClient();
    
    private:
      MySocket IRCSock;
    };
    If the MySocket class was:

    Code:
    #include "MySocket.h"
    
    class MySocket
    {
    public:
      MySocket();
      ~MySocket();
    
    private:
      SOCKET temp;
    };

    Would MySocket.temp store the socket if MySocket.Connect() consisted of temp = socket(AF_INET ..etc)?

    And would the IRCClient class be able to access the socket properly?
    ie.
    Code:
    int IRCClient::Connect(server, ip) {
    IRCSock.SetServer(server);
    IRCSock.SetIP(ip);
    return IRCSock.Connect();
    }
    or

    Code:
    int IRCClient::RecvData() {
       string buffer = IRCSock.GetData();
    }
    with the above function something similar to

    Code:
    string MySocket::GetData()
    {
        char sockbuff[512];
        return recv(temp, sockbuff, 512,0);
    }
    As you can see im still a noob to C++, but if you could point me in the right direction or provide an example (simpler the better..) of how to implement this, then id appreciate it. Oh and if possible please tell me what this is actually called also? (storing class objects?)

    Thanks

    Edit: For information, this isnt for an assignment or homework, this is for teaching myself C++ and to create a IRCBot which monitors and admins game servers from a channel, along with storing player information from servers into a MySQL database.
    Last edited by avidkaos999; 01-07-2012 at 11:57 AM.

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    20
    Never mind, managed to work it out. Still not familiar with what this method is actually called though? Could someone tell me please?

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-15-2010, 07:53 PM
  2. Array of class objects
    By te5la in forum C++ Programming
    Replies: 4
    Last Post: 07-23-2008, 05:37 PM
  3. Array of class objects
    By GCNDoug in forum C++ Programming
    Replies: 29
    Last Post: 03-26-2008, 04:30 PM
  4. Replies: 4
    Last Post: 10-16-2003, 11:26 AM
  5. base class pointer to derived class objects
    By curlious in forum C++ Programming
    Replies: 4
    Last Post: 09-28-2003, 08:39 PM