Friend classes in the same namespace

43 Views Asked by At

I was programming Vulkan based renderer but unfortunately this error appeared: 'Azazel::Instance::~Instance': cannot access private member declared in class 'Azazel::Instance' It gives me a headache. I tried to predeclare Azazel_Menager class at start of my namespace, but it did not work as well so I changed:

friend class Azazel_Menager;

to:

friend class Azazel::Azazel_Menager;

well it did not do the trick as well. So here I'm asking for your help. maybe you will see something I did not.

Azazel_Menager:

#pragma once
#include "Engine/Core/UsingTypes.h"
namespace Azazel
{
    class Instance;
    class PhysicalDevice;

    class Azazel_Menager
    {
    public:
        static void CreateInstance();
        static void RetrieveAndSetPhysicalDevice();
    private:
        static Ref<Instance> s_Instance;
        static Ref<PhysicalDevice> s_PhysicalDevice;
    };
}

Instance.h:

#pragma once
#include <vector>
#include <VulkanSDK/include/vulkan/vulkan.hpp>
namespace Azazel
{
    class Azazel_Menager;
    class Instance
    {
        friend class Azazel::Azazel_Menager;
    private:
        Instance();
        ~Instance();
    public:
        vk::UniqueInstance m_Instance;
        VkDebugUtilsMessengerEXT m_callback;
    };
}

Ref = std::shared_ptr

1

There are 1 best solutions below

5
Jarod42 On

You probably use constructor/destructor outside of Azazel_Menager (as in std::make_shared or in default Deleter).

You have to use them exclusively in Azazel_Menager, as:

void Azazel_Menager::CreateInstance()
{
    s_Instance = std::shared_ptr<Azazel::Instance>{new Azazel::Instance{},
                                                   [](auto* p){ delete p; }};
}

Demo