为什么类型别名在C++中不允许作为友元类名?

问题描述 投票:0回答:1
class A {    
};

class B {
    using C = A;

    // Compilation error: 
    // Type alias 'C' cannot be referenced with a class specifier 
    friend class C;    
};

为什么类型别名在C++中不允许作为友元类名?

背后的原理是什么?

c++ c++11 types friend type-alias
1个回答
0
投票

为什么类型别名在 C++ 中不允许作为友元类名?

您认为不允许类型别名成为友元的假设是错误的。正确的语法是

friend C
而不是
friend class C;

© www.soinside.com 2019 - 2024. All rights reserved.