在使用不同版本的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/