I got the problem with virtual methods of my C++ projects.
First of all i got the class graphics which presents:
#pragma once
class gameGraphics
{
public:
gameGraphics();
~gameGraphics();
virtual void paint();
};
and i got two classes, first one :
class brick
: public gameGraphics
{
protected:
int R, G, B;
bool ifDelete;
public:
brick();
~brick();
virtual void paint(int x, int y);
};
And the second one:
class superBrick :
public brick, public gameGraphics
{
private:
int bonusType;
public:
superBrick();
~superBrick();
void paint(int x, int y);
};
Then im trying to paint objects of this two classes, when my projects runs it shows error: "Unhandled exception at 0x74D3CB49 in project.exe: 0xC0000005: Access violation executing location 0x00000000.", while trying paint function for superBrick object.
for (int i = 0; i < WIDTH; i++)
{
for (int k = 0; k < LENGTH; k++)
{
temp = &table[k][i];
temp->paint(k, i);
}
}
I dont know what is the reason of this error, i think i did the Polymorphism good.
Sorry for my english, thanks for reading and help!
Have a good night!
EDIT:
class of table here:
class gameTable : public gameGraphics
{
private:
brick** table;
public:
gameTable();
~gameTable();
void paint(int CordX, int cordY);
};
virtual.table. Can you create this error with a singlesuperBrickobject?table. I recommend reading How to Debug Small Programs to get a better idea of how to debug this.ifDeleteflag, (5) no use ofconst, (6) apparently using macros for constants, likeWIDTH, (7) needless use of pointers (liketemp), (8) use of raw arrays instead of e.g.std::vector, (9) double-star