C++ template method forward declaration -
i'm having little problem classes. have 2 classes both use template methods, therefore have put in header. here example. i'd compile without "forward declaration incomplete" problem. understand wrong can't figure how correct this. thank guys.
class.h
class a; class b; class { b *foo; template <class t> void func() { foo->fanc(); } } class b { *foo; void fanc(); template <class t> void osef() { foo->func<int>(); } }
you have circular dependence. can not declare object of incomplete class. can solve declaring either pointers or references incomplete class.
class { b* foo;
or
class { b& foo;
on later case have initialize reference member initialization list of constructor.
if using pointer should move definition of memeber function after definition of incomplte class.
class a; class b; class { b* foo; template <class t> void func(); }; class b { // ... }; template <class t> inline void a::func() ^^^^^^ // if need include header in more 1 source file. { foo->fanc(); }
Comments
Post a Comment