1

Tried to create a forward declaration for boost::gil::rgba8_image_t:

namespace boost::gil {
    class rgba8_image_t;
}

And got this:

... 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 ...

How to create new forward declaration for the boost::gil::rgba8_image_t properly?

Sergei Krivonos
  • 4,217
  • 3
  • 39
  • 54

1 Answers1

0

Caution

Forward declarations of highly generic types doesn't really help. You won't be able to interact with them unless you do include the definitions.

If the goal is to do interface abstraction, consider using your own interface type which hides everything GIL related:

struct MyInterface {
   struct image_t;

   void do_something_with(image_t&, int);
};

Where in your CPP file you will define it without any further complications:

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

What Is The Technical Issue?

rgba8_image_t is an alias defined as

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

It does require the other types, so you might do it that way. Here's is the smallest subset I could quickly isolate:

#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

Even Simpler: Predefined Typedefs Header

GIL comes with a header to create all these forward declarations, for all pixel layouts etc. In fact, it's the header that you can see in the error message:

#include <boost/gil/typedefs.hpp>

Now you can already use rgba8_image_t& in your interfaces as an incomplete type.

sehe
  • 374,641
  • 47
  • 450
  • 633