C++:在嵌套名称说明符中命名的不完整类型

标签 c++

我正在尝试解决我的 C++ 项目中的循环依赖,并且根据 StackOverflow 上的其他答案,我遵循了相同的方法。但是,我仍然看到一个问题:

下面是我的代码片段:

// In ip6.hh
namespace net
{
    class Inet4;

      /** IP6 layer */
      class IP6
      {
         using Stack = class Inet4;

         void set_packet_forwarding(Stack::Forward_delg fwd)
         { forward_packet_ = fwd; }

         Stack& stack_;
     }
}

// In Inet4.hpp
#include "ip6/ip6.hpp" 
namespace net {

  class Inet4 : public Inet<IP4>{

  IP6& ip_obj()
  { return ip6_; }

   IP6    ip6_;
  }
}

在 main.cpp 中,我将其包含如下:

#include <net/ip6/ip6.hpp>
#include <net/inet4.hpp>
> /home/nikhil/projects/ipv6/IncludeOS/api/net/ip6/ip6.hpp:84:32: error:
> incomplete type 'net::Inet4' named in nested name specifier
>     void set_packet_forwarding(Stack::Forward_delg fwd)
>                                ^~~~~~~ /home/nikhil/projects/ipv6/IncludeOS/api/net/ip6/ip6.hpp:35:9: note:
> forward declaration of 'net::Inet4'   class Inet4;

最佳答案

只有 Inet 声明(不是定义)。编译器不知道 Inet4 的定义(因此 Stack 被称为 Inet4)。

关于C++:在嵌套名称说明符中命名的不完整类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49938102/

相关文章:

c++ - 什么时候使用引用成员?

C++ 用 SFINAE 重载泛型函数

c++ - 套接字 RECV 陷入循环

c++ - 将多个文件编译在一起?

c++ - 从矩阵中查找距离 k 内的元素

c++ - 构造函数帮助 const C 字符串数组

c++:没有强制转换的包含对象的确切类型

c++ - 为什么我可以通过静态指针调用非静态函数?

C++ 如何访问 SMB NAS 文件?

c++ - Linux/CUPS 打印示例/教程?