0

I´m currently trying to wrap the LibRealsense into a Unreal 4 Plugin. This lib provides some C API as well as some C++ API (wrapping it´s C API), so I´m doing C++ (which makes sense for Unreal).

But there is a kind of operator overloading I´ve never seen before (in rs_pipeline.hpp):

class pipeline
{
public:

    pipeline(context ctx = context())
...
    operator std::shared_ptr<rs2_pipeline>() const
    {
        return _pipeline;
    }

private:
    context _ctx;
    std::shared_ptr<rs2_pipeline> _pipeline;
}

rs2_pipeline is the C-type of a pipeline, it is accessed in all the c++ classes as a shared pointer. E.g:

 class config
 {
 public:
 ...
     bool can_resolve(std::shared_ptr<rs2_pipeline> p) const
 ...
 }

So when I´m trying to call config.can_resolve with my C++ ´pipeline´ object, I need to get the internal shared_ptr<rs_pipline>. But how do I call operator shared_ptr<rs_pipline()?? And what kind of operator is it exactly?

daKenpachi
  • 19
  • 2
  • 1
    It's a [*user-defined conversion operator*](https://en.cppreference.com/w/cpp/language/cast_operator), also known as a "cast operator". – Some programmer dude Aug 22 '18 at 10:36
  • Thanks, now I know what it is! =) In fact, my first try was just writing `config.can_resolve(pipeline)` without fully understanding what it is. But it didnt´work because my `pipline` was a pointer, so so the compiler said the types are incompetible.... Now it works with `config.can_resolve(*pipline)` – daKenpachi Aug 22 '18 at 14:12

0 Answers0