C++ 模板参数/类歧义

标签 c++ templates standards

在使用不同版本的g++进行测试时,出现以下问题

template<class bra>
struct Transform<bra, void> : kernel::Eri::Transform::bra {
        static const size_t ni = bra::A::size;

bra::A 被 g++ 4.1.2 解释为 kernel::Eri::Transform::bra::A,而不是模板参数。另一方面,g++ 4.3 是正确的。

根据标准,什么是正确的行为?

同时,我稍微重构一下以解决问题。

最佳答案

在我看来,gcc 4.1.2 是正确的。 §14.6.1/7(ISO/IEC 14882,C++03):

In the definition of a class template or in the definition of a member of such a template that appears outside of the template definition, for each base class which does not depend on a template-parameter (14.6.2), if the name of the base class or the name of a member of the base class is the same as the name of a template- parameter, the base class name or member name hides the template-parameter name (3.3.7).

关于C++ 模板参数/类歧义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2767329/

相关文章:

c++ - 删除和替换 CAtlArray 中间的对象指针

c++ - Boost Zlib的解压缩在Windows上崩溃

c++ - 如何正确特化与其父类型相同的模板化静态常量成员

c++ - 如何使用最小包含创建一个用模板函数包装对象的库?

从 double 到 int 的转换可以用可移植的 C 编写吗

c++ - 相同的着色器在 Nvidia 和 ATI 卡上表现不同

c++ - 使用 GDB 调试英特尔 C++ 编译代码

c++ - 模板对象声明和初始化: manually call template constructor to bypass standard constructors calls order

c++ - 为什么线程从未作为 C++ 标准的一部分包含在内?

pdf - 日期字符串的正确格式是什么?