Reputation: 2427
I'm having some slight problems with the declaration of a derived Constructor in a header file and its definition in a *.cpp file
my header file:
class Nrpeoutputquery : public Query
{
private:
std::string queryText;
std::string queryType;
public:
//default Constructor
Nrpeoutputquery();
//Constructor
Nrpeoutputquery(std::string queryText, std::string queryType, sql::Connection *connection) : Query(connection);
//Destructor
~Nrpeoutputquery();
};
my *.cpp file
namespace nrpeout
{
Nrpeoutputquery::Nrpeoutputquery()
{
}
Nrpeoutputquery::Nrpeoutputquery(std::string queryText, std::string queryType, sql::Connection *connection) : Query(connection)
{
this->queryText = queryText;
this->queryType = queryType;
}
Nrpeoutputquery::~Nrpeoutputquery()
{
}
}
I'm getting a compilation error:
Nrpeoutputquery(std::string queryText, std::string queryType, sql::Connection *connection) : Query(connection);
Nrpeoutputquery.h:19:112: error: expected ‘{’ at end of input
Apparently the compiler expects the definition of the Constructor in the header file. The problem doesn't appear with the definition of Constructors which are inheriting fields from the standard Constructor of the base class.
So: Is there any way to not declare the Constructor of a derived class using the non-standard constructor of the base class directly in the header file?
Upvotes: 1
Views: 1176
Reputation: 117886
In you declaration, change this
Nrpeoutputquery(std::string queryText, std::string queryType, sql::Connection *connection) : Query(connection);
To
Nrpeoutputquery(std::string queryText, std::string queryType, sql::Connection *connection);
When you add : Query(connection)
you are calling the base class's constructor using the initialization list, so it thinks you are providing the full constructor definition, instead of just the declaration.
Upvotes: 2
Reputation: 311028
The constructor must be declared like
Nrpeoutputquery(std::string queryText, std::string queryType, sql::Connection *connection );
You have to remove the mem-initializer list : Query(connection)
from the constructor declaration.
Upvotes: 4