Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ - circular dependence (using inner type of subclass in templated base class)

I run into problem with circular dependence in a templated class. There is a code sample:

template <typename T> struct A 
{
  typedef typename T::C D;
  //typename T::C c;
};

struct B : public A<B>
{
  struct C {};
};

When I try to instantiate B, I get a compiler error: 'C' is not a member of 'B' (MSVC) or Invalid use of incomplete type 'struct B' (GCC).
What is the best way to change the sample to get it to work?

like image 668
Loom Avatar asked Aug 28 '12 05:08

Loom


1 Answers

struct B_base { struct C {}; };
strucr B : A<B_base>, B_base { };
like image 133
n. 1.8e9-where's-my-share m. Avatar answered Nov 12 '22 13:11

n. 1.8e9-where's-my-share m.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!