有
Bar.h
template<class T>
class Bar<T> {
//...
}
oo
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;
}
如您所见,我需要包含bar.h,但是由于循环依赖的原因,我无法在我的项目中添加它。
因此,就像我通常所做的那样,我只是在.h中编写定义,在.cpp中编写实现,但是此示例存在一些问题,因为我不知道带有模板的类的语法。
有什么语法吗?我在当前示例中遇到以下编译器错误:
Bar is not a class template
正向声明语法为
template<T> class Bar;
因此,您的代码变为:
oo
template<T> class Bar;
template<class T>
class Foo {
...
private:
Bar<T> *_bar;
};
#include "Foo.inl"
富尔
#include "bar.h"
// Foo implementation ...
Bar.h
template<class T>
class Bar<T> {
//...
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句