![]() |
| | #1 |
| Registered User Join Date: Feb 2006
Posts: 1
| Need help to build network class I'm currently working a Network class. For the moment, I have a class containing the following functions : Code: class cNetwork
{
cnetwork();
cnetwork(int port);
~cnetwork();
void send_to(char *buffer,int length);
int receive_from(char *buf,int buf_size);
void bind_to(void);
void wait_connection(void);
};
When I have a server, if I accept a connection, a new socket number is created, so I need to have 2 socket variable in the class. It's not needed when I have to use a client connection. So, I would like to build the following inheritance of class: parent : cNetwork (containing the socket and receive_from / send_to functions) childrens : cNetwork_server (containing the bind, accept...) cNetwork_client (containing the connect and other usefull functions to search the dns etc...) This mean the cNetwork_server class need to access to the socket variable of the parent class. Is this a good practice to use ? Can you see another way to do this ? Any advice ??? Here the code of the class to be sure everybody can understand what I would like to do: Code: class cNetwork
{
public:
cNetwork();
~cNetwork();
void send_to(char *buffer,int size);
int receive_from(char *buffer,int size);
protected:
int socket;
};
class cNetwork_server : cNetwork
{
/* I must use the variable socket of the parent class withing the functions of this class */
cNetwork_server();
~cNetwork_server();
void bind_to();
void wait_for_connection();
};
class cNetwork_client : cNetwork
{
/* I must use the variable socket of the parent class withing the functions of this class */
cNetwork_client();
~cNetwork_client();
void connect_to();
};
|
| weeb0 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PlaySound | cangel | C++ Programming | 16 | 10-08-2009 05:29 PM |
| matrix class | shuo | C++ Programming | 2 | 07-13-2007 01:03 AM |
| Screwy Linker Error - VC2005 | Tonto | C++ Programming | 5 | 06-19-2007 02:39 PM |
| structure vs class | sana | C++ Programming | 13 | 12-02-2002 07:18 AM |
| Abstract class problem | VanJay011379 | C++ Programming | 9 | 07-31-2002 01:30 PM |