Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bwrsandman opened this issue Apr 12, 2022 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@bwrsandman
Copy link

bwrsandman commented Apr 12, 2022

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

@rpavlik rpavlik added enhancement New feature or request help wanted Extra attention is needed labels Dec 7, 2022
@rpavlik
Copy link
Contributor

rpavlik commented Dec 8, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants