Posted on 2011-07-09 22:52
逐渐 阅读(1982)
评论(0) 编辑 收藏 引用
下面是示例代码,在vs2010下编译成功,但在linux下编译报错。
基类com_alg代码片段:
1 template <typename real_para>
2 class com_alg
3 {
4 public:
5 com_alg(std::string conf_path)
6 {
7 //![](http://www.cppblog.com/Images/dot.gif)
8 }
9 virtual ~com_alg() { }
10 }; 子类de_alg代码片段:
1 #include "com_alg.h"
2
3 class de_alg
4 :public com_alg<de_para>
5 {
6 public:
7 de_alg(std::string conf_path):
8 com_alg(conf_path)
9 {
10 }
11 ~de_alg() { }
12 };
注意de_alg代码第8行红色部分,在vs2010下编译通过,但是在linux(g++ 4.4.3)下编译出错:
de_alg.h: In constructor ‘de_alg::de_alg(std::string)’:
de_alg.h:30: error: class ‘de_alg’ does not have any field named ‘com_alg’
de_alg.h:30: error: no matching function for call to ‘com_alg<de_para>::com_alg()’
com_alg.h:29: note: candidates are: com_alg<real_para>::com_alg(std::string) [with real_para = de_para]
com_alg.h:27: note: com_alg<de_para>::com_alg(const com_alg<de_para>&)
将代码改为
com_alg<de_para>(conf_path)编译通过,大家能帮忙解释下不?