|
-
March 14th, 2007, 11:54 AM
#1
Inheritance and using static variables
code begin:
connection.h // base class
class Connection{
private:
static int clientSockfd;
static int serverSockfd;
public:
Connection() {};
int getClientSockfd{return clientSockfd;};
int getServerSockfd{return serverSockfd;};
void setClientSockfd(int val) {clientSockfd=val;};
void setServerSockfd(int val) {serverSockfd=val;};
};
client.h // client class
class Client : public Connection {
public:
Client(){};
void processMessageMT6523();
};
client.cpp //
int main(....) {
Client *myClient;
int sockfd;
sockfd = socket(.....);
myClient->setClientSockfd(sockfd);
// I put this statement in to debug...at this point server will have already
kicked of and should have set it's sockfd via the "setServerSockfd" I
just wanted to print out the value i always get 0 which is wrong.
cout << "Server Sockfd --> " << myClient->getServerSockfd() << endl;
}
server.h // server class
class Server : public Connection {
public:
Server(){};
void processMessageMT4590;
};
server.cpp //
int main(....) {
Server *myServer;
int sockfd;
sockfd = socket(.....);
myServer->setServerSockfd(sockfd);
}
code end:
I kick off the server first so it can set its sockfd, but when i try to access "serverSockfd" via the "myClient->getServerSockfd()" i get 0.
What am i missing?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|