Aug 13, 2014 at 5:12am UTC
This code works just fine:
http://coliru.stacked-crooked.com/a/01104ebeeee1be3f 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
template <typename T>
struct ReallyVerboseName
{
ReallyVerboseName(T const &){}
virtual ~ReallyVerboseName() = default ;
};
template <typename T>
struct Derived1
: virtual ReallyVerboseName<T>
{
using RVN_t = ReallyVerboseName<T>;
virtual ~Derived1() = 0;
};
template <typename T>
Derived1<T>::~Derived1<T>() = default ;
//template<typename T>
struct Derived2
: Derived1</*T*/ int >
{
Derived2(/*T*/ int const &t)
: RVN_t(t)
{
}
};
int main()
{
Derived2/*<int>*/ {7};
}
However, as soon as I make Derived2 a template, it fails to compile:
http://coliru.stacked-crooked.com/a/6ad9a828b6afe6b4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
template <typename T>
struct ReallyVerboseName
{
ReallyVerboseName(T const &){}
virtual ~ReallyVerboseName() = default ;
};
template <typename T>
struct Derived1
: virtual ReallyVerboseName<T>
{
using RVN_t = ReallyVerboseName<T>;
virtual ~Derived1() = 0;
};
template <typename T>
Derived1<T>::~Derived1<T>() = default ;
template <typename T>
struct Derived2
: Derived1<T>
{
Derived2(T const &t)
: RVN_t(t)
{
}
};
int main()
{
Derived2<int >{7};
}
main.cpp:24:7: error: member initializer 'RVN_t' does not name a non-static data member or base class
: RVN_t(t)
^~~~~~~~
What's going on here?
Last edited on Aug 13, 2014 at 5:18am UTC
Aug 13, 2014 at 5:34am UTC
Ah so would what I have above be considered part of "temporary" solution compilers accept, or is that a special case where it can be determined that it's not a static variable?
Aug 13, 2014 at 5:34am UTC
Ah, I was thinking it had to do with dependent names. Thanks JLBorges! That solution preserves the terseness I was going for.