C++ and virtual methods overriding
- by silent
Sorry for this stupid question, but I can't find an answer by myself, I'm too new in C++ :(
class DBObject : public QObject
{
...
protected:
virtual QString tableName() { return ""; };
};
class DBUserObject : public DBObject
{
...
protected:
virtual QString tableName() { return "profiles"; };
};
And I have this code in parent:
bool DBObject::load(quint32 id)
{
QString query = QString("select %1 from %2 where id = :id")
.arg(fieldList().join(","))
.arg(tableName()); <--- here is trouble
...
}
So I'm trying to execute:
DBUserObject user;
user.load(3);
But in result I have a query with empty table name cause tableName() method returns empty string.
Why not "profiles"?