I have some template class that has two private static members. Users define a traits struct and provide it to the template class, which then derives from it.
Then in a c++ file the user define the static members, with one member initialized from the other. For some reason I get a "class has not been declared" error if I dont fully specify the namespace for the arg. This is only an issue when I'm in a nested namespace, there is no issue if you define the type in a single top level namespace, which makes me think this is a compiler bug. Trimmed down example below, compiling with gcc 7.2
template<typename Traits>
struct Base
{
static int x;
static int y;
};
namespace foo::bar
{
struct BarTraits
{
};
using Bar = Base<BarTraits>;
template<> int Bar::x = 0;
template<> int Bar::y( Bar::x ); //error
//template<> int Bar::y( foo::bar::Bar::x ); //no error
}
Base
is defined in. Or actually borrow them fromTraits
template parameter directly. – Jacobbax
, saying cannot define or redeclare 'x' here because namespace 'bar' does not enclose namespace 'Base<foo::bar::BarTraits>' – Jolyntemplate<> int Bar::y( Bar::x );
doesn't define a static data member with an initializer. You can't use round parentheses for an initializer here. – Achromatic