Having
Bar.h
template<class T>
class Bar<T> {
//...
}
Foo.h
template<T>
class Bar<T>;
//#include "Bar.h" removed due of circular dependencies, I include it in .cpp file
template<class T>
class Foo {
...
private:
Bar<T> *_bar;
}
As you can see, I need to include bar.h but I can't do it on my project for circual dependencies reasons..
So as I usually do, I just write definition in .h and implementation in .cpp But I have some issues with this example, because I don't know the syntax for class with template..
Is there any syntax for this? I'm getting the following compiler error with the current example:
Bar is not a class template
template<typename T> class Bar {};
andtemplate<typename T> class Bar
; as a definition and forward declaration respectively. P.S definition of a template must be present in every translation unit. – 101010