结合“使用”部分重载的指令:gcc 功能还是 intel 错误?
我希望将一组用 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。
I wish to use a set of libraries written in C++ with the Intel compilers. I've attached sample code which demonstrates the problem. There are many places in the libraries where they make use of combining the 'using' directive with partial overloading (e.g., I want to use the foo(void) method from the base class but reimplement the second version fo foo in the derived class). gcc does not have a problem but intel does.
#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
}
The compiler error that icc gives is:
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)
If you remove the line
using Base<F>::foo;
and replace it with the line
void foo (void) { Base<F>::foo(); }
everything works fine.
My question is does anyone know if this is a special gcc feature or icc bug? Or is there another work around which would not involve changing the code?
This is with g++.real (Ubuntu 4.4.3-4ubuntu5) 4.4.3 and icc (ICC) 12.0.2 20110112.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 C++11,相关标准引用可以在
这支持基于 EDG 的编译器。然而,有一种特殊情况是在类中使用的:
因此,在 C++11 中,Comeau 和 Intel 似乎是错误的。我不知道这些规则是否同样适用于C++03
For C++11, the relevant Standard quote can be found in
This supports the EDG-based compilers. However, a special case is meant for use in classes:
Therefore, in C++11, it seems Comeau and Intel are wrong. I do not know whether these rules equally applied in C++03