I have a class called server
with server.h
as follows:
class Server : public QTcpServer
{
Q_OBJECT
public:
Server(QHostAddress listenAddress, quint16 listenPort, QObject *parent = 0);
QHostAddress hostAddress;
quint16 hostPort;
protected:
void incomingConnection(qintptr socketDescriptor);
private:
};
and server.cpp
as follows (partial):
Server(QHostAddress listenAddress, quint16 listenPort, QObject *parent = 0)
: hostAddress(listenAddress), hostPort(listenPort), QTcpServer(parent)
{
}
The problem is that I wanted to keep hostAddress
and hostPort
private. However, when I made them private in the class declaration, the compiler complained that my constructor initialization was not allowed to change these private members. Why? Isn't the constructor within the same class, so it should be able to change private variables?