C++ で記述された一連のライブラリーを Intel コンパイラーで使用したいと考えています。問題を示すサンプル コードを添付しました。ライブラリには、'using' ディレクティブと部分的なオーバーロードを組み合わせて利用する場所がたくさんあります (たとえば、基本クラスから foo(void) メソッドを使用したいが、派生クラスで foo の 2 番目のバージョンを再実装したい)。 . gcc には問題はありませんが、Intel には問題があります。
#include <iostream>
template <class F>
struct Interface
{
static const F f=10;
};
template <class F>
struct Base : public Interface<F>
{
void foo (void) { std::cout << "void" << std::endl; }
template <class FF>
void foo (Interface<FF> &ii) { std::cout << "F : " << ii.f << std::endl; }
};
template <class F,int i>
struct Derived : public Base<F>
{
// void foo (void) { Base<F>::foo(); } // works fine
using Base<F>::foo; // gives error
template <class FF>
void foo (Interface<FF> &ii) { std::cout << "Derived<" << i << "> F : " << ii.f << std::endl; }
};
int main (void)
{
Derived<double,10> o;
o.foo(); // ok
o.foo (o); // problem
}
icc が与えるコンパイラ エラーは次のとおりです。
test.cc(30): error: more than one instance of overloaded function "Derived<F, i>::foo [with F=double, i=10]" matches the argument list:
function template "void Base<F>::foo(Interface<FF> &) [with F=double]"
function template "void Derived<F, i>::foo(Interface<FF> &) [with F=double, i=10]"
argument types are: (Derived<double, 10>)
object type is: Derived<double, 10>
o.foo (o); // problem
^
compilation aborted for test.cc (code 2)
ラインを外すと
using Base<F>::foo;
そしてそれを行に置き換えます
void foo (void) { Base<F>::foo(); }
すべて正常に動作します。
私の質問は、これが gcc の特別な機能なのか icc のバグなのかを知っている人はいますか? または、コードの変更を伴わない別の回避策はありますか?
これは、g++.real (Ubuntu 4.4.3-4ubuntu5) 4.4.3 および icc (ICC) 12.0.2 20110112 を使用しています。