0

So I have the following:

// PE.hpp
#include <memory>
#include <string>

namespace pe { namespace managers {
    class WindowManager;
}}

namespace pe { namespace engine {
    class PE {
    private:
        std::unique_ptr<pe::managers::WindowManager> mp_windowManager;

    public:
        PE(const std::string& windowTitle, windowWidth, windowHeight);
        ~PE() = default;
    };
}}

// PE.cpp
#include "engine/managers/WindowManager.hpp"

namespace pe { namespace engine {
    PE::PE(const std::string& windowTitle, int windowWidth, int windowHeight) :
    mp_windowManager(std::make_unique<pe::managers::WindowManager>(windowTitle, windowWidth, windowHeight)) {
    }
}}

// WindowManager.hpp
namespace pe { namespace managers {
    class WindowManager {
    private:
        int m_windowWidth, m_windowHeight;
        std::string m_windowTitle;

    public:
        WindowManager(const std::string& windowTitle, int windowWidth, int windowHeight);
        ~WindowManager() = default;

        /**
         * Manager setter and getter functions that are inline
         */
}}

// WindowManager.cpp
#include "engine/managers/WindowManager.cpp"

namespace pe { namespace managers {
    WindowManager::WindowManager(const std::string& windowTitle, int windowWidth, int windowHeight) :
    m_windowTitle(windowTitle),
    m_windowWidth(windowWidth),
    m_windowHeight(windowHeight) {
    }
}}

Now when I use a raw pointer this works absolutely fine. But when I use the example above, it comes out with the following error:

/usr/include/c++/7/bits/unique_ptr.h: In instantiation of ‘void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = pe::managers::WindowManager]’:
/usr/include/c++/7/bits/unique_ptr.h:268:17:   required from ‘std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = pe::managers::WindowManager; _Dp = std::default_delete<pe::managers::WindowManager>]’
/home/jamie-rhys/CLionProjects/PsychoEngine/PsychoEngineCore/includes/engine/PsychoEngineCore.hpp:26:16:   required from here
/usr/include/c++/7/bits/unique_ptr.h:76:22: error: invalid application of ‘sizeof’ to incomplete type ‘pe::managers::WindowManager’
  static_assert(sizeof(_Tp)>0,

I've tried searching for what could possibly going wrong and tried to rectify it but for the life of me I cannot find why.

I've done what said examples have told me to do and ensured I have a dtor in WindowManager, both as default and placing it in the .cpp.

Any ideas?

Thanks

  • 1
    You need to have the definition of `~PE()` destructor where `WindowManager` is a complete type (which is to say, in `PE.cpp`). That destructor destroys `mp_windowManager`, which in turn needs to know how to destroy the owned object. – Igor Tandetnik Sep 03 '18 at 19:28
  • It still doesn't work whether I have the definition of ~PE() within WindowManager.cpp or whether I default it. – Jamie Edwards Sep 03 '18 at 20:58
  • Am I really missing something blatantly obvious here? – Jamie Edwards Sep 04 '18 at 21:34
  • You must be doing something wrong. I can't say what - my crystal ball is cloudy lately, I can't see your screen very well from here. Does the article marked as duplicate not answer your question? – Igor Tandetnik Sep 05 '18 at 04:30

0 Answers0