I have two classes called Player and Enemy both inheriting from a class called GameObject, how do I store them both in an array of type GameObject while still keeping their own unique information?
I tried making an array like this:
std::vector<GameObject> _gameObjList;
and then tried pushing a test object in it like this:
testObject test;
_gameObjList.push_back(test);
but then it gave me the following exception error:
Error C2664 'void std::Vector<GameObject *,std::allocator<_Ty>>::push_back(_Ty &&)': cannot convert argument 1 from 'testObject *' to 'GameObject *const &' OpenGLFramework c:\users\name\projects\myproject\gamemanager.cpp 11
so basically it's saying that the types should be the same, even though my testobject inherits from GameObject.
Here is my testObject header file:
#pragma once
#include "GameObject.h"
class testObject : public GameObject
{
public:
testObject();
testObject(float xPosition, float yPosition, float zPosition);
void Update();
~testObject();
};
There isn't really anything in the cpp file that goes with it except the constructor and update method but those are all empty at the moment so I don't think it's necessary to show them here.
I hope anyone here can explain me the proper way to do this and/or can point out the error(s) in my code. I just want to have an arraylist of all my gameobjects so I can add/remove objects easily.