S
Song Yun Zhao
hi, just wondering what ppl do in a situation like this:
say I have a class:
class Socket {
public:
void connect(string host, int port);
private:
string host;
int port;
}
Socket::connect(string host, int port)
{
host = host;
port = port;
}
The problem is that the private member data is the same as the function
argument. although C/C++ permits this, I am not sure if this is a good
idea. I really like to use lower case for my variables and intuitive names.
I am tempted to add a lower score "_" to the end of my private variables
like this:
host_ = host
port_ = port
But I read somewhere this is not recommended because libraries need to
do this and might pollute namespaces.
What do you reckon?
Song
say I have a class:
class Socket {
public:
void connect(string host, int port);
private:
string host;
int port;
}
Socket::connect(string host, int port)
{
host = host;
port = port;
}
The problem is that the private member data is the same as the function
argument. although C/C++ permits this, I am not sure if this is a good
idea. I really like to use lower case for my variables and intuitive names.
I am tempted to add a lower score "_" to the end of my private variables
like this:
host_ = host
port_ = port
But I read somewhere this is not recommended because libraries need to
do this and might pollute namespaces.
What do you reckon?
Song