c++前向声明

前向声明的几种方式

前向声明

    class A:
    A f();

详细类型声明

    class A f();

两种方式的区别

  • 前向声明

      struct s { int a; };
      struct s; // does nothing (s already defined in this scope)
      void g() {
          struct s; // forward declaration of a new, local struct "s"
                    // this hides global struct s until the end of this block
          s* p;     // pointer to local struct s
          struct s { char* p; }; // definitions of the local struct s
      }
    
  • 详细类型说明

      class U;
      namespace ns{
          class Y f(class T p); // declares function ns::f and declares ns::T and ns::Y
          class U f(); // U refers to ::U
          Y* p; T* q; // can use pointers and references to T and Y
      }
    

    详细类型说明,只有在查找不到对应名字的同类型的东西,才会引入前向声明的效果。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值