Say i have the following class :
class Abc {
int id;
public:
int getID() { return id; }
int setID(int id) { this->id = id; }
};
Is there any logical error in this ? I seem to be getting unexpected results (read : wrong values of id). I know this is not the way to write a getter .. but still there shudn't be any error in this code ?
Here is the class declaration :
class ClientConn {
static int num;
short pos;
sockaddr_in tcpAddress;
sockaddr_in udpAddress;
int connFD;
public:
ClientConn();
int getConnFD();
void setConnFD(int connFD);
void setPos(short pos);
short const& getPos();
void setUdpAddress(short port);
void setTcpAddress(sockaddr_in address);
void setUdpAddress(sockaddr_in address);
void setTcpAddress(short port, char* serverIP);
void setUdpAddress(short port, char * serverIP);
sockaddr_in const& getTcpAddress() const;
sockaddr_in const& getUdpAddress() const;
};
the two functions had been defined as follows :
int ClientConn :: getConnFD() {
return connFD;
}
void ClientConn :: setConnFD(int connFD) {
this->connFD = connFD;
}
I had set the value of connFD to 7 using the setter, and then when i was using the getter, i was getting the value 65534.
(Should i answer my question or keep editing my post ? im new)