samedi 12 septembre 2020

C++ : How to declare a template class without defining it [closed]

I've two template classes and both of them have multiple constructors. Both template class have a constructor with other template class as it's parameter.

template<typename T = int_fast64_t>
class A
{
    T a;
public:
    A():a(0){}
    A(const B& b): a(b.get()){}
    T get(){return a;}
};

template<typename T = double>
class B
{
    T b;
public:
    B():b(0.0){}
    B(const A& a): b(a.get()){}
    T get(){return b;}
};

I'm also attaching a screenshot : Similar code scenario

The issue I'm facing is if template class A is created first then for it template class B won't exist for it's constructor argument. I've tried all possible things that made sense to me but always got some error. The only way in my mind is if I could declare template class without defining it, then I could just declare both next to each other and then define it together.

I'm open to all available methods. Thank you

Aucun commentaire:

Enregistrer un commentaire