依赖基类中的常量使线外定义不匹配? [英] a constant in dependent base class make out-of-line definition not matched?
问题描述
template<template<typename, size_t>class V, typename, size_t N>
struct X{
static constexpr size_t stride = N;
};
template<typename Num, size_t N>
struct Y;
template<typename Num>
struct Y<Num, 3> : protected X<Y, Num, 3>{
using X<Y, Num, 3>::stride;
Y<Num, stride> foo(Num angle, Y<Num, stride> axis) const;
};
我尝试为 foo
提供一个定义,例如:
I try to provide a definition for foo
like:
1.
template<typename Num>
Y<Num, 3> Y<Num, 3>::foo(Num angle, Y<Num, 3> axis) const{};
template<typename Num>
Y<Num, Y<Num, 3>::stride> Y<Num, 3>::foo(Num angle, Y<Num, Y<Num, 3>::stride> axis) const{};
template<typename Num>
Y<Num, X<Y, Num, 3>::stride> Y<Num, 3>::foo(Num angle, Y<Num, X<Y, Num, 3>::stride> axis) const{};
,但编译器(clang,msvc和gcc 7.5-)均不接受它们.(为什么要使用gcc 8.1 +?)
but none of them is accepted by compilers (clang, msvc, and gcc 7.5-). (why gcc 8.1+ works?)
但是如果我在 Y
处定义 stride
,例如 static constexpr size_t stride = X< Y,Num,3> :: stride
, 1 和 2 工作.
but if I define stride
at Y
like static constexpr size_t stride = X<Y, Num, 3>::stride
, 1 and 2 work.
或者如果 X
不是类模板,它们也可以正常工作.
or if X
is not a class template, they work as well.
是什么原因?标准声明的错误还是编译器错误?以及如何在使用X :: stride 的情况下在上工作?
what's the reason? a mistake declared by standard or just a compiler bug? and how to work at the using X::stride
situation?
代码: https://godbolt.org/z/asn8rj .
推荐答案
This is, ominously, CWG2, a lack of specification in the standard whose filing date has literally been forgotten. That said, your option #2 seems clearly the correct choice, since it names the same using-declaration as the declaration in the class.
这篇关于依赖基类中的常量使线外定义不匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!