KhronosGroup/OpenXR-Hpp

Forward declare header can't be used to forward declare Unique Handles

bwrsandman opened this issue · 1 comments

I'm trying to use the forward headers to limit the scope of my include of openxr.hpp by only using it in one cpp file.
Normally to do this, you forward declare your classes in the header files and include the full headers in the cpp files.

From the docustring, I would expect to be able to use Unique Handles like a unique ptr.

Template class for holding a handle with unique ownership, much like unique_ptr.

Below is an example, it would work if using an std::unique_ptr because the undefined deleter is referenced in the cpp file and not the header.

A.hpp

#pragma once
#include <openxr/openxr_handles_forward.hpp>
struct A {
    A();
    virtual ~A();
    xr::UniqueInstance m_instance;
};

A.cpp

#include "A.h"
#include <openxr/openxr.hpp>
A::A() = default;
A::~A() = default; // Here the deleter is defined and since it has visibility of openxr.hpp it should be okay

In practice, you get the following errors because the forward header implements functions that need full visibility of the forward declared classes and even holds an instance of the type in question.

openxr/openxr_handles_forward.hpp(140,18): error C2027: use of undefined type 'xr::Instance'
openxr/openxr_handles_forward.hpp(140,32): error C3646: 'getRawHandle': unknown override specifier
openxr/openxr_handles_forward.hpp(151,18): error C2027: use of undefined type 'xr::Instance'
openxr/openxr_handles_forward.hpp(170,8): error C2079: 'xr::UniqueHandle<xr::Instance,xr::DispatchLoaderStatic>::m_value' uses undefined class 'xr::Instance

An awkward workaround is to make m_instance into a std::unique_ptr<xr::UniqueInstance>.

Hmm, good catch. I'm not sure the best way to do this, it's been a while since I looked at the unique handles code.

You shouldn't need to include the whole openxr.hpp anymore, though, that's just a convenience header that includes other stuff and has some documentation for doxygen.