我希望在英特尔编译器中使用一组用 C++ 编写的库。我附上了演示问题的示例代码。库中有很多地方使用了将“using”指令与部分重载结合使用(例如,我想使用基类中的 foo(void) 方法,但在派生类中重新实现第二个版本 fo foo) . 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。