In C++, a type alias is not allowed to be a friend class name because the syntax for befriending a type alias is different from that of befriending a class.
To befriend a type alias, you use the following syntax:
friend C;
where C
is the type alias.
On the other hand, to befriend a class, you use the following syntax:
friend class C;
where C
is the class name.
The reason for this difference in syntax is that a type alias is not a class. It is simply an alias for another type. Therefore, it does not have the same properties as a class, and it cannot be befriended in the same way.
If you try to befriend a type alias using the syntax for befriending a class, you will get a compiler error. The compiler will tell you that the type alias is not a class and cannot be befriended.
To fix this error, you need to use the correct syntax for befriending a type alias. Here is an example:
class B { public: friend C; // Befriend the type alias C private: int x; }; typedef int C; // Define the type alias C
In this example, the type alias C
is befriended by the class B
. This means that the class B
can access the private members of the type alias C
.