zhujian

揣着梦想骑驴找马但不虐待驴
posts - 10, comments - 7, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

Linux和Windows编译C++模板问题

Posted on 2011-07-09 22:52 逐渐 阅读(1964) 评论(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         //
 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)编译通过,大家能帮忙解释下不?

欢迎大家访问我们的开源项目,关于粒子群演化算法的库,多多提意见--http://code.google.com/p/stupidalgorithm/

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理