vukung
vukung

Reputation: 1884

Variable with the same name as a class - invalid?

struct A
{
};

struct B
{
  using A_t = A;
  A_t A;
};

This code compiles happily with clang++ (14.0.6), while g++ (12.2.0) issues the following error:

naming.cpp:8:7: error: declaration of ‘B::A_t B::A’ changes meaning of ‘A’ [-fpermissive]
    8 |   A_t A;
      |       ^
naming.cpp:1:8: note: ‘A’ declared here as ‘struct A’
    1 | struct A
      |        ^

So who's right? (I stumbled into this at the abby library.)

In this question the answers deal with the type and variable (with the same name) appearing on the same line, but here this is prevented by the using declaration.

Upvotes: 1

Views: 99

Answers (0)

Related Questions