I'm working on a project for a c++ class I'm taking and I can't figure out some compiler errors. My file is supposed to write a base class sprite, that has polymorphic function draw that 4 other classes inherit from. However I can't figure out these compiler issues!
main.cpp: In function ‘int main()’:
main.cpp:72:47: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x [enabled by default]
main.cpp:72:47: error: assigning to an array from an initializer list
main.cpp:73:23: error: expected primary-expression before ‘)’ token
main.cpp:74:21: error: expected primary-expression before ‘)’ token
main.cpp:75:22: error: expected primary-expression before ‘)’ token
main.cpp:76:20: error: expected primary-expression before ‘)’ token
main.cpp:81:13: warning: deleting array ‘Sprite array [4]’ [enabled by default]
Here's my code!
#include "drawing.h"
class Sprite
{
friend class Shadow;
friend class Speedy;
friend class Bashful;
friend class Pokey;
private:
int row;
int col;
public:
int getCol()
{
return col;
}
int getRow()
{
return row;
}
void setPosition(int x, int y)
{
row = x;
col = y;
}
virtual void draw()
{
drawErrorMessage(row, col);
}
};
class Shadow: public Sprite
{
public:
virtual void draw()
{
drawShadow(row,col);
}
};
class Speedy: public Sprite
{
public:
virtual void draw()
{
drawSpeedy(row,col);
}
};
class Bashful: public Sprite
{
public:
virtual void draw()
{
drawBashful(row,col);
}
};
class Pokey: public Sprite
{
public:
virtual void draw()
{
drawPokey(row,col);
}
};
int main()
{
Sprite array[4];
beginDrawing();
array = {Shadow(),Speedy(),Bashful(),Pokey()};
((Shadow) (array[0]*)).setPosition(5,10);
((Speedy)(array[1]*)).setPosition(5,44);
((Bashful)(array[2]*)).setPosition(22,44);
((Pokey)(array[3]*)).setPosition(22,10);
array[0].draw();
array[1].draw();
array[2].draw();
array[3].draw();
delete [] array;
endDrawing();
}