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
{
};