![]() |
|
#1
|
|||
|
|||
Generic searching through vectorsHi guys,
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? |
|
#2
|
|||
|
|||
Re: Generic searching through vectorsIt 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... vector<Shapes*> allshapes_ptr; 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; allshapes_ptr.pushback(square_ptr); now searching only needs to go through one vector type. i rock. ![]() |
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to commute values of vectors | cpit | CPP / C++ Forum | 4 | 23-Jun-2006 08:27 |
| vectors of references | mirizar | CPP / 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 | CPP / C++ Forum | 2 | 20-Mar-2004 09:02 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The