So I have three classes
class Map that stores objects of class Recty
class Map : public GameObject, public InCollisionMap
{
public:
void Setup();
private:
Recty *tile[24][32];
};
class InCollisionMap //interface for map
{
InCollisionRect *tile[24][32];
public:
virtual InCollisionRect* Tile(int n, int m){
int n = 0;
int m = 0;
return tile[n][m]; //returns object of class Recty
}
InCollision();
~InCollision();
};
class Recty that stores variable type
class Recty : public GameObject, public InCollisionRect
{
private:
int type;
public:
Recty();
~Recty();
};
class InCollisionRect //interface for class Recty
{
private:
int type;
public:
virtual int get_number(char num);
InCollisionRect();
~InCollisionRect();
};
and finally class GameObject
class GameObject : public InCollisionObject
{
public:
GameObject(const char* textureSheet, SDL_Renderer* ren, int x, int y);
GameObject();
~GameObject();
private:
int xpos;
int ypos;
int way;
SDL_Texture* objTexture;
SDL_Rect srcRect, destRect;
SDL_Renderer* renderer;
};
class InCollisionObject // interface for GameObject
{
int xpos;
int ypos;
int way;
SDL_Texture* objTexture;
SDL_Rect srcRect, destRect;
SDL_Renderer* renderer;
public:
virtual void Collision_Loop(InCollisionMap* target){
if (target->Tile(i, j)->get_number('t') == 0 {
^
/*{Tile(i,j) returns nullptr}*/
cout<<"NO<<endl;"
}
InCollisionObject();
~InCollisionObject();
};
and main
GameObject* player;
Map map;
int main(){
map.Setup();
player->Collision_Loop(&map);
}
I kind of simplified the code but that every object in array *tile is initialized properly. Array is full of objects.
I am getting this error in Collision_Loop()
Exception thrown: read access violation.
InCollision::Tile[virtual](...) returned nullptr.
Why does it returns a nullptr? And how do I fix this?