Pattern Interdependence

struct A template {typedef float atype; typedef typename tB :: btype typeB; }; template struct B {typedef float btype; typedef typename tA :: atype typeA; };

struct MyB;
struct MyA: public A<MyB>{};
struct MyB: public B<MyA>{};

int main(int argc, char *argv[])
{
}

does not compile because "main.cpp: 6: error: invalid use of incomplete type 'struct MyB".

Basically, the compiler cannot solve the loop because the definition of A depends on the definition of B and vice versa. Is there any way to figure this out? thank,

+3
source share
3 answers

. ( ), : ++: " " ?

: , , ( , ).

+3

, , typedef'ing tB:: btype, struct MyB, ( ). : , tA:: atype struct B, , typedef typeB struct A, .

, , ?

+1

, , , . ( ). , myA myB, , , myA, , , myB .. - ...

: , , ( ). , , AST, , - - , myA:: myB:: myA:: myB:: myA:: myB:: myA:: myB... myB:: btype ( myA::atype, myA::tA myB::tB) . , , , .

+1

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


All Articles