This is part of the header-file for a class:
1 2 3 4 5 6 7 8 9 10 11 12
|
class BasexClient {
public:
BasexClient (const std::string&, const std::string&, const std::string&, const std::string&);
virtual ~BasexClient();
...
void Create(const std::string & dbName, const std::string & content = "");
QueryObject * Query(const std::string & query, BasexSocket * socket);
BasexSocket * getSocket();
private:
BasexSocket *Socket;
|
And this is part of a test-file:
1 2 3 4 5 6 7 8 9 10
|
int main() {
std::string DBHOST = "localhost";
std::string DBPORT = "1984";
std::string DBUSERNAME = "Test";
std::string DBPASSWORD = "<testPassword>";
BasexClient Session (DBHOST, DBPORT, DBUSERNAME, DBPASSWORD);
std::string query { "This is a test" };
QueryObject * Q_Object = Session.Query(query, Session.getSocket());
|
After a BasexClient-object has been created (Session), this variable can be used to create a QueryObject (Q_Object). This QueryObjectobject uses the same socket as the session. Each session can use multiple QueryObjects.
It is possible to create multple BasexClient-objects, each with a unique socket.
I want to remove the Session.getSocket() argument from line 10 in the test-file and add a default value.
As in line 6 from BasexClient.h, I tried to add a default-argument to line 7:
|
QueryObject * Query(const std::string & query, BasexSocket * socket = Socket);
|
But when I compile this class, I get this error:
invalid use of non-static data member ‘BasexClient::Socket’ |
.
The 'Socket' member can't be made static since it is not shared by all the BasecClient-objects.
How can I add a default value for the socket?
Ben