boost::gil::rgba8_image_t 前向声明

问题描述 投票:0回答:1

试图为

boost::gil::rgba8_image_t
创建前向声明:

namespace boost::gil {
    class rgba8_image_t;
}

得到这个:

... error: definition of type 'rgba8_image_t' conflicts with type alias of the same name
[build]     class rgba8_image_t;
[build]           ^
[build] /usr/include/boost/gil/typedefs.hpp:207:1: note: 'rgba8_image_t' declared here
[build] BOOST_GIL_DEFINE_ALL_TYPEDEFS(8, uint8_t, rgba)
[build] ^
[build] /usr/include/boost/gil/typedefs.hpp:112:9: note: expanded from macro 'BOOST_GIL_DEFINE_ALL_TYPEDEFS'
[build]         BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(B, CM, CS, CS##_t, CS##_layout_t)                   \
[build]         ^
[build] /usr/include/boost/gil/typedefs.hpp:72:5: note: expanded from macro 'BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL'
[build]     BOOST_GIL_DEFINE_BASE_TYPEDEFS_INTERNAL(B, CM, CS, LAYOUT)                                     \
[build]     ^
[build] /usr/include/boost/gil/typedefs.hpp:62:11: note: expanded from macro 'BOOST_GIL_DEFINE_BASE_TYPEDEFS_INTERNAL'
[build]     using CS##B##_image_t = image<CS##B##_pixel_t, false, std::allocator<unsigned char>>;
[build]           ^
[build] <scratch space>:10:1: note: expanded from here
[build] rgba8_image_t
[build] ^
[build] In file included from ...

如何正确地为 boost::gil::rgba8_image_t 创建新的前向声明?

c++ boost forward-declaration boost-gil
1个回答
0
投票

注意

高度通用类型的前向声明并没有真正帮助。除非您包含定义,否则您将无法与他们互动。

如果目标是进行接口抽象,请考虑使用您自己的接口类型,它隐藏了与 GIL 相关的所有内容:

struct MyInterface {
   struct image_t;

   void do_something_with(image_t&, int);
};

在您的 CPP 文件中,您可以在没有任何进一步复杂化的情况下定义它:

struct MyInterface::image_t {
   // using GIL freely here, without even leaking GIL namespace usage in the header
};

什么是技术问题?

rgba8_image_t
是定义为

的别名
using rgba8_image_t = image<rgba8_pixel_t, false, std::allocator<unsigned char>>;

它确实需要其他类型,所以你可以那样做。这是我可以快速隔离的最小子集:

#include <boost/gil/rgba.hpp>

namespace boost::gil {
    template <typename, typename> struct pixel;
    template <typename, bool, typename> class image;
    using rgba8_pixel_t = pixel<uint8_t, rgba_layout_t>;
    using rgba8_image_t = image<rgba8_pixel_t, false, std::allocator<unsigned char>>;
} // namespace boost::gil

更简单:预定义的 Typedefs 标头

GIL 带有一个标题来创建所有这些前向声明,用于所有像素布局等。事实上,它是您可以在错误消息中看到的标题:

#include <boost/gil/typedefs.hpp>

现在您已经可以在您的界面中使用

rgba8_image_t&
作为不完整类型。

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