Skip to content

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

Description

@bwrsandman

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions