[odb-users] automatically detect abstract class instantiated from a template

Sten Kultakangas ratkaisut at gmail.com
Mon May 14 05:15:07 EDT 2018


Hello

The documentation provides the following example:

#pragma db object abstract
class base_common
{
...
#pragma db id auto
unsigned long id;
};
template <typename T>
class base: public base_common
{
...
T value;
};

typedef base<std::string> string_base;
#pragma db object(string_base) abstract

#pragma db object
class derived: public string_base
{
...
};


The problem is that the string_base definition seems to be redundant and
can induce problems with codebase maintainability. When writing new code it
is easy to make a typo in those two lines which can create a hard to
diagnose runtime error in some scenarios (my base class template uses
dynamic_cast<T *>(this)). I'm considering making changes to the odb
compiler making the above string_base definition unnecessary because it is
possible to see that base<std::string> inherits base_common which is
defined as an abstract database object.

Is there a reason why the current odb release candidate does not detect
such condition and requires explicit definition of the parent class as an
abstract database object ?

The aim is to make the following definition possible without additional
types:

#pragma db object
class derived: public base<std::string>
{
...
};




Best regards,
Sten Kultakangas


More information about the odb-users mailing list