Pattern Inheritance Issues

I am having problems with a very strange error in some code that I wrote. The basic idea of ​​the code can be trivialized 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 main idea is that pointers are replaced with the Ptr class (this will ultimately be used in MPI configuration, so standard pointers are virtually useless). Pointers are for a β€œpoint” in the base class and therefore can point to any inherited class (as shown in the example).

Can anyone think of any reason that may not work in a non-trivial case (but the case when the architecture of the object remains identical).

The error that occurs 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]);
};

( ) MPICXX:
Ptr&lt;double, double>::Ptr(Derived&lt;double, double>*)
., ( )
Ptr&lt;f, g>::Ptr(Base&lt;f, g, Ptr&lt;f, g> >*) [with f = double, g = double]

,

EDITED ( , ​​ )

+3
3

, Ptr , Base Derived.

, , , ! =]

+1

, :

class BasePtr
{
public:
    virtual void* obj() = 0;
};

template <class T>
class Ptr :: public BasePtr
{
public:
    Ptr() : ptr(0) {};
    Ptr(T* a) : ptr(a) {};
    virtual T* obj() { return ptr; }
protected:
    T* ptr;
};

BasePtr , , Base .

template <class a, class b >
class Base
{
public:
    Base(){};
    void set_ptr( BasePtr* );
};

DDerived dd = DDerived();
Ptr<double,double> p(&dd);
dd.set_ptr( p );

, , .

0

.

template <class a, class b, template <class aa, class bb> class c = Ptr >
class Base
{
typedef Ptr<a, b> pointer;
public:
    Base(){};
};
0

Source: https://habr.com/ru/post/1703809/


All Articles