List:MySQL++« Previous MessageNext Message »
From:Warren Young Date:July 2 2008 12:01pm
Subject:Re: Derive a structure and use it with storein
View as plain text  
On Jul 2, 2008, at 3:56 AM, Loïc Dardant wrote:

> class User : public database::User
> {
> public:
>    User(mysqlpp::sql_varchar a, mysqlpp::sql_varchar b,  
> mysqlpp::sql_int c
> );
>    ~User();
>    void foo();
> };

In C++, if a derived class has a function with the same name as one in  
the base class, the derived class's versions always hide those in the  
base class.  Thus, your single ctor in the derived class hides these  
ctors defined in the base SSQLS:

User();	// default ctor, needed by STL containers
User(const mysqlpp::Row& row); // what your error is about
User(const mysqlpp::sql_varchar& a); // for-comparison ctor

You need to define all of these in your derivative for it to be a true  
SSQLS.  Their implementation can be trivial: just call the base class  
ctors of the same signature, passing along the parameters directly.

Technically, the one ctor you do have hides a similar one in the base  
SSQLS: the full-initialization ctor takes its parameters by const  
reference, not by value.  You should redefine your one existing ctor  
like so:

User(const mysqlpp::sql_varchar& a, const mysqlpp::sql_varchar& b,  
const mysqlpp::sql_int& c);

Failing to match this signature won't prevent good code from  
compiling, but taking the parameters by reference is more efficient in  
the case of stringish data types.  And if you're going to take them by  
reference, making them const references is simply a matter of  
correctness, since you aren't actually modifying the referents.
Thread
Derive a structure and use it with storeinLoïc Dardant2 Jul
  • Re: Derive a structure and use it with storeinWarren Young2 Jul
    • Re: Derive a structure and use it with storeinLoïc Dardant2 Jul