I have 2 very simple classes and both need to perform a canDelete() method. How can I "insert" such method so I only define it once and also without the overhead of runtime polymorphism?
The classes are:
1 2 3 4 5 6 7 8 9 10 11 12 13
struct Statement
{
int id_statement;
date::sys_days date;
bool canDelete();
};
struct Concepto
{
int id_concepto;
std::string name;
int fkey_account;
bool canDelete();
};
bool canDelete() is implemented exactly the same so I don't want to duplicate its code and I want to use templates to achieve this (i do not want runtime polymorphism).
Something like this code would apparently work but it does not compile (you can get the gist by looking at this):