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