0

I use a library (which I cannot modify) and that declares a PointCloud template that includes a Ptr typedef

namespace pcl
{
    template <typename PointT>
    class PCL_EXPORTS PointCloud
    {
        ...
        typedef boost::shared_ptr<PointCloud<PointT> > Ptr;
    }
}

Now, I need to forward declare Ptr and I have no idea how to. I have done

namespace pcl
{
    class PointXYZ;
    template<class pointT> class PointCloud;
}

but I am stuck here and whatever I do, I do not seem to be able to forward declare the Ptr typedef.

Any idea?

----------EDIT----------

The reason why I need this forward declaration is that I need to declare a function into a header of my own. And I am expecting this function to take a PointCloud< PointXYZ >::Ptr as argument, because the PointCloud I want to feed into the function is stored into a PointCloud< PointXYZ >::Ptr.

arennuit
  • 855
  • 1
  • 7
  • 23
  • 2
    You cannot do this. – DeiDei Feb 19 '18 at 17:11
  • 7
    What's the actual problem that you're trying to solve? Hacking around with your own declarations of a library's classes and their members is almost always not the right answer. – Pete Becker Feb 19 '18 at 17:12
  • 1
    I dont understand why you think you need to predeclare a typedef. Maybe it is my confusion, but if you know how to declare it, you dont need the typedef in the first place, no? – 463035818_is_not_an_ai Feb 19 '18 at 17:16
  • I have added an edit which should give more details. – arennuit Feb 19 '18 at 17:23
  • 2
    Then just use `boost::shared_ptr >` in your function? Or you can make the function a template, and make it use `boost::shared_ptr >` for any kind of `T`. – super Feb 19 '18 at 17:37
  • Well, you can probably use alias instead... but you cannot use existing typedef so if the library changes, you have to update your declarations... – Phil1970 Feb 19 '18 at 17:37
  • 4
    The usual way to do that is for your header to `#include` the header that has the definitions of `PointCloud`, then just declare the function to take `PointCloud::Ptr`. – Pete Becker Feb 19 '18 at 17:47
  • 1
    Five bucks says this whole thing ends with an explanation of `typename` for dependent types. – Sneftel Feb 19 '18 at 17:54
  • @Sneftel: I am not sure I understand your statement... – arennuit Feb 19 '18 at 17:59
  • 2
    You can just forward declare the type, and if you want, make YOUR OWN typedef, `using LibFooPtr = boost::shared_ptr;` ? Your type def does not need to be identical to the library type def. – Chris Beck Feb 19 '18 at 18:27
  • I got a few different relevant answers here, thanks! – arennuit Feb 20 '18 at 08:33

1 Answers1

2

Typedefs are aliases for types. They are not types themselves, if that makes sense.

namespace pcl
{
  class PointXYZ;
  template<class pointT> class PointCloud;
}
template<class T>
using foo = boost::shared_ptr<pcl::PointCloud<T>>;

foo<X> is the same type as pcl::PointCloud<T>::Ptr.

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524