程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Linux和Windows編譯C++模板問題

Linux和Windows編譯C++模板問題

編輯:C++入門知識

下面是示例代碼,在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>&)

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved