How can I call a member data for a class from its cpp file ?
How can I call a member data for a class called Connection from, its cpp file
Connection.cpp ?
I would like to set the member data of hSocket and ServerAddress for the class Connection
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
void Init_Connection( const char * ip, unsigned short PORT)
{
// Create the TCP socket
SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
this-> hSocket = hSocket; // error
// Create the server address
sockaddr_in serverAddress = { 0 };
serverAddress.sin_family = AF_INET;
serverAddress.sin_port = htons(PORT);
serverAddress.sin_addr.s_addr = inet_addr(ip);
Connection::serverAddress = serverAddress; // error
std::cout << "Connecting to Client with IP " << ip << std::endl;
}
|
if Init_Connection belongs to a class then you should scope it with the class name if the definition is outside the class.
e.g if the class name is Connection do something similar to this.
1 2 3 4
|
void Connection::Init_Connection( const char * ip, unsigned short PORT)
{
///you can set the class members without errors.
}
|
Last edited on
Topic archived. No new replies allowed.