I'm following the example from here, however I am using templates and calling a constructor of one of the derived classes. The following code works without templates but when included I am not sure why I get the following error:
: error: no matching function for call to ‘AbsInit<double>::AbsInit()’
NotAbsTotal(int x) : AbsInit(x) {};
^
Here is the code:
#include <iostream>
using namespace std;
template<typename T>
class AbsBase
{
virtual void init() = 0;
virtual void work() = 0;
};
template<typename T>
class AbsInit : public virtual AbsBase<T>
{
public:
int n;
AbsInit(int x)
{
n = x;
}
void init() { }
};
template<typename T>
class AbsWork : public virtual AbsBase<T>
{
void work() { }
};
template<typename T>
class NotAbsTotal : public AbsInit<T>, public AbsWork<T>
{
public:
T y;
NotAbsTotal(int x) : AbsInit(x) {};
}; // Nothing, both should be defined
int main() {
NotAbsTotal<double> foo(10);
cout << foo.n << endl;
}