Making an undefined class as friend, and defining it later

后端 未结 3 2050
礼貌的吻别
礼貌的吻别 2021-01-12 15:05

Making an unknown friend

template
class List
{
protected:

    class a {
        int x;
        int y;
    private:
        friend class b;         


        
3条回答
  •  伪装坚强ぢ
    2021-01-12 15:16

    The code is ill-formed and Comeau rejects it giving the following error

    error: invalid redeclaration of type name "b" (declared at
          line 11)
    

    I think this is a bug in g++. Intel C++ rejects it too. You can fix the code by defining class B above A.

    template  class b { 
            int z;
            U y;
    };
    class a {
            int x;
            int y;
        private:
            friend class b;  
    };
    

提交回复
热议问题