0

I'm getting this error from this constructor

Severity Code Description Project File Line Suppression State Error
(active) E0289 no instance of constructor "std::unique_ptr<_Ty, _Dx>::unique_ptr [with _Ty=InputComponent, _Dx=std::default_delete<InputComponent>]" matches the argument list

Code:

    class GameWorldObject 
    {
    public:

    GameWorldObject::GameWorldObject(std::unique_ptr<GraphicsComponent> graphicsComponent, std::unique_ptr<LogicComponent> logicComponent, std::unique_ptr<InputComponent> inputComponent)
        :
        m_graphicsComponent( std::move(graphicsComponent) ), // ERROR
        m_inputComponent( std::move(logicComponent) ), // ERROR
        m_logicComponent( std::move(inputComponent) ) // ERROR
    {}



        // these auto initialize to null
        std::unique_ptr<GraphicsComponent> m_graphicsComponent;
        std::unique_ptr<LogicComponent> m_logicComponent;
        std::unique_ptr<InputComponent> m_inputComponent;

    };

I'm dumb stuck because this example works for me and seems identical to the previous:

    struct Animal {
        virtual ~Animal() {}
        virtual void speak() = 0;
    };


    struct Dog : Animal {
        void speak() override { std::cout << "Woof!\n"; }
    };

    std::unique_ptr<Animal> createPet() {
        return std::make_unique<Dog>();

    }

    class House {
    public:
        House(std::unique_ptr<Animal> pet) // seems identical
            :
            m_pet(std::move(pet)) // seems identical
        {}

        std::unique_ptr<Animal> m_pet; // seems identical
    };

    void main()
    {

        auto pet = createPet(6.0);
        pet->speak();

        House house(std::move(pet));

        //pet->speak(); err pet is nullptr
        house.m_pet->speak();
    }

What the difference between these two? Why is the top one not working?

Note I have not implemented any kind of constructor, destructor, or copy constructor in InputComponent, GraphicsComponent, or LogicComponent.

In fact, this is InputComponent

class InputComponent
{

};
melpomene
  • 79,257
  • 6
  • 70
  • 127
  • 1
    `void main()` isn't valid in C++. It must always be `int main()` or `int main(int argc,char* argv[])` ? – Destructor Aug 04 '18 at 06:15
  • 1
    "*Note I have not implemented any kind of constructor, destructor, or copy constructor*". What happens if you implement a constructor? – kiner_shah Aug 04 '18 at 06:24
  • 1
    do you use forward declarations? – Marek R Aug 04 '18 at 09:09
  • Turn on warnings. Fix warnings. Code compiles. In `m_inputComponent( std::move(logicComponent) )` a logic component is not a input component. – Eljay Aug 04 '18 at 13:15
  • @Eljay wow, I looked at this for over an hour... How do you "turn on warnings"? What did you mean by that? – Wesley Richmond Aug 04 '18 at 16:40
  • For my platform, I turn on warnings by using `alias c17='/usr/bin/clang++ -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -std=c++17'` – Eljay Aug 06 '18 at 17:43

0 Answers0