0

Why is this code causing a compiler error??

template <size_t N>
class A
{
    bitset<N> _bits;
    void foo(bitset<N>::reference* ref) // this does not compile
    {
        //some code
    }
};

Is N != сonstexpr in this situation??

Error: C2061 syntax error: indentifier 'reference'

doctal
  • 1
  • 1
  • please include the error message – kmdreko Oct 31 '20 at 18:52
  • It needs to be `typename bitset::reference*` – Artyer Oct 31 '20 at 18:53
  • @Artyer: It really helped. Could You tell exactly how this helped and why? – doctal Oct 31 '20 at 22:04
  • @doctal Because if you have `template struct bitset { using reference = ...; }`, you could theoretically have a specialisation `template<> struct bitset<5> { static int reference; }` where `reference` isn't the name of the type. In this ambiguous case with a dependent name, the compiler always assumes that the name is a value rather than a type, and of course a value doesn't make sense there. The `typename` forces it to be parsed as a type instead. – Artyer Nov 01 '20 at 03:37

0 Answers0