Jump to content
  • Advertisement
Sign in to follow this  

Programming help

This topic is 4746 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to create a simple array of various types of geometric entities. The purpose is to define something in terms or arcs and lines while holding the data in a single array, rather than an array of lines and an array of arcs for example class arc { ...arc class } class line { ..line class } then in the program entity[0]=arc or line class; entity[1]=arc or line class (can be different type from previous spot in array; etc. these classes are not derived from each other at this time although I would not rule out doing so. Can anyone steer me in the right direction on how to achieve a really simple container of sorts.

Share this post


Link to post
Share on other sites
Advertisement
maybe something like this:


class Shape
{
virtual void Draw() = 0;
};

class Arc : public Shape
{
Draw();
}

class Line : public Shape
{
Draw();
}

Shape **shapes = new Shapes[2];
shapes[0] = new Line();
shapes[1] = new Arc();

Share this post


Link to post
Share on other sites
will that work?

each class has different members
ex

class line
{

private:
float x1, x2, y1, y2;

...
member functions that deal with these private members for line
}

class arc{

private:
float centerx, centery, theta1, theta2 , radius;

...
member functions that deal with these private members for line
}

Share this post


Link to post
Share on other sites
Yup, it should work as long as all of the derived classes implement teh virtual Draw function. When you call draw on a shape, it will actually call the derived class's draw function, which should do what you want, regardless of the different member variables.

Share this post


Link to post
Share on other sites
say i have a function:

float ArcAngle()
{
return theta1-theta2;
}

in my arc but this function would not be needed in the line class

would I need a virtual function in my base class:

virtual float ArcAngle()=0;

Thanks for your help

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!