error: nested name specifier for declaration does not refer into a class, class template or class template partial specialization

chatlanin

Why error about "error: nested name specifier 'h::TYPE::' for declaration does not refer into a class, class template or class template partial specialization" show is only mark place?

#include <iostream>

namespace h
{
  enum TYPE 
  {
    A, B, C
  };

  struct test
  {
    test(TYPE type = B) { std::cout << type << std::endl; }
  };
};

int main() 
{
  h::test t{h::TYPE::A};
  h::test r(h::TYPE::A);
  h::test {h::TYPE::A};
  h::test (h::TYPE::A); <--- only here
}

DEMO

chatlanin

As I found out from my colleagues. C++ is a pretty funny language. Mainly due to its long history. The meaning of the compilation error is that the problematic line of code: h::test (h::TYPE::A);

The compiler parsed as "creating a variable of type h::test with the name h::TYPE::A". And then the compiler goes crazy, because you can't call variables that way.

All this is because someone once decided that it might be convenient to declare variables in this

int (value) style;
value = 42;
std::string (str);
str = "hello";

In other cases, the compiler parses the code correctly - it understands that this is a call to the constructor of the h::text class.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Does the use a simple-template-id in a nested-name-specifier unambiguously mean a class template specialization?

Partial specialization of nested template template class

Nested class template specialization

Clang partial class template specialization error

specialize a template class using a nested name specifier of another template class

Partial specialization of nested class on enum defined inside a template class

Class template partial specialization equivalence

Template class partial specialization syntax

Error: class template partial specialization contains a template parameter that cannot be deduced

`template <auto>` and partial class template specialization ordering

Specialization of inherited nested template class

Nested class template specialization issue

specialization of template template paremeter of template class for nested template class

class template specialization with template

something confusing about class template partial specialization & class member specialization

explicit specialization in template class error

Template class specialization with template class

Partial class template specialization c++11

Class template specialization partial ordering and function synthesis

Class template argument deduction with partial specialization

Is noexcept deduction allowed in class template partial specialization?

Partial specialization or instantiation of template class method

Partial Template specialization definition outside of class definition

Partial specialization of a class template member function

Partial specialization of a nested class

explicit specialization of a function template (which is a member of a class template) produces "partial specialization is not allowed" error, why?

template class specialization : template-id does not match any template declaration

Class Template with Nested Class Declaration (C++)

Forward declaration of a class nested in in a class template, is it legal?