I have the following classes. An error occurs during the for loop in the Main class. The compiler complains about the draw function "is of non-type GLCommand". The idea of the application is to store many different types of GLCommand and Shape within the same vector. Should I take a different design approach, or is their a simple fix to this problem?
Interface:
class GLCommand
{
public:
GLCommand();
virtual ~GLCommand();
virtual void draw() = 0;
};
Abstract Class:
class Shape : public GLCommand
{
public:
Shape(int);
virtual ~Shape();
virtual void draw() {};
private:
double colour[];
int sides;
};
Derived class:
class Polygon : public Shape
{
public:
Polygon(int sides);
virtual ~Polygon();
void draw();
private:
vector<Coordinates *> verticies;
};
Main:
int main()
{
vector <GLCommand*> vec;
Polygon p(4);
vec.push_back(&p);
for (vector<GLCommand*>::iterator it = vec.begin(); it!=vec.end(); ++it)
{
*it->draw();
}
return 0;
}
Nothing you said is relevant; the problem is just operator precedence:
(*it)->draw();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With