I'm having issues with a very strange error in some code I wrote. The basic idea behind the code can be trivialised in the following example:
template <class f, class g> class Ptr;
template <class a, class b, class c = Ptr<a,b> >
class Base
{
public:
Base(){};
};
template <class d, class e>
class Derived : public Base <d,e>
{
public:
Derived(){};
};
template <class f, class g>
class Ptr
{
public:
Ptr(){};
Ptr(Base<f,g,Ptr<f,g> >* a){};
};
typedef Derived<double,double> DDerived;
int main()
{
Base<int,int> b = Base<int,int>();
Derived<double,double> d = Derived<double,double>();
DDerived dd = DDerived();
Ptr<double,double> p(&dd);
return 1;
}
The basic idea is that pointers are replaced by the Ptr class (This will eventually be used in an MPI setting so standard pointers are effectively useless). The pointers are designed to 'point' at the base class, and so can point at any inherited class (as demonstrated in the example).
Can anyone think of any reason this might not work in a non-trivial case (But a case where the object architecture remains identical).
The error that is occurring in the main case is as follows:
void function()
{
vector nVector(1); // cut down for simplicity
nVector[0].SetId(1); // To ensure the node is instantiated correctly
Ptr temp(&nVector[1]);
};
This code produces the (slightly extended version of the) error when compiled with MPICXX:
no matching function for call to Ptr<double, double>::Ptr(Derived<double, double>*)
candidates are . . . (Some removed for simplicity's sake)
Ptr<f, g>::Ptr(Base<f, g, Ptr<f, g> >*) [with f = double, g = double]
Cheers, Ed
EDITED (Detailing the error a little better, added info on the compiler)