Generic searching through vectors
Ive spent the last four hours working on this... time to turn to the forum.
This query is really complicated... it'l take time to work through.
Thanks very much to anyone that tries.
I'm using STL and SDL.
I have a base class called Shapes.
A number of shapes inherit this base class... eg square, circle etc...
In my main program, i create vectors of all the specific shapes.
i need to do a search to find the co-ordinates of a shape.
how do you create a generic searching algorithm, that scans
through any vector, regardless of the class/object/type the vector
holds, and checks the co-ordinates of the shape?
god i hope this makes sense.
ofcourse, im only searching through shapes, thus all the vectors
have the base class Shape. I cant seem to pass a specific shape vector and catch it as a generic shape vector. the error i cant get around is instantiating
an abstract class Shape.... code to follow:
CPP / C++ / C Code:
so where have i gone wrong... well i know... i cant create an object
thats pure virtual... but how do i get around that without writing a
search method for every single vector?
Re: Generic searching through vectors
It came to me in a blinding flashing light - which was infact
a cars headlights when i fell asleep behind the wheel after
getting no sleep trying to finish the program by the deadline.
For those who cared... here's the simple solution...
Don't create multiple vectors of different derived classess....
Instead create one vector of pointers of the base class...
then each time u make a new shape... just create a new pointer
of that particular shape and push it onto the generic vector list...
Square* square_ptr = new Square;
now searching only needs to go through one vector type.
|Thread Tools||Search this Thread|
|Rate This Thread|
|Thread||Thread Starter||Forum||Replies||Last Post|
|how to commute values of vectors||cpit||C++ Forum||4||23-Jun-2006 08:27|
|vectors of references||mirizar||C++ Forum||1||12-Apr-2005 02:02|
|new domain searching tool.||johnpmccann||Websites Reviewed Forum||1||06-Jun-2004 10:37|
|Declaring a vector of vectors?||Lethal411||C++ Forum||2||20-Mar-2004 09:02|