0

Possible Duplicate:
How can I store objects of differing types in a C++ container?

After reading a text file...

The following information is available

Point2D, [3, 2]
Line3D, [7, 12, 3], [-9, 13, 68]
Point3D, [1, 3, 8]
Line2D, [5, 7], [3, 8]
Point2D, [3, 2]
Line3D, [7, -12, 3], [9, 13, 68]
Point3D, [6, 9, 5]
Point2D, [3, 2]
Line3D, [70, -120, -3], [-29, 1, 268]
Line3D, [25, -69, -33], [-2, -41, 58]
Point3D, [6, 9, -50]

The first data separate by the delimiter comma is the class name. for each of the 4 class

Point2D,Line3D,Point3D,Line2D

How do i like store them into relevant object base on their class means..

when it read first line

Point2D, [3, 2]

It will store it as Point2D object with the Data [3, 2]

But the issue is what dataset should i pick, Vector, Set , Map or List

I was thinking to actually create a data set then but i can't use new Point2D(); since

Point2D is parent of Point3D
Line2D is parent of Line3D

and theres no parent class of Point2D and Line2D. how can i like create a object of them in a data set like e.g Vector

so Vector[0] is of Point2D class with data [3,2] , then Vector[1] is of Line3D class with data [7, 12, 3], [-9, 13, 68]

Thanks for helping.!

Community
  • 1
  • 1
user1777711
  • 1,604
  • 6
  • 22
  • 32
  • 1
    It looks like you've asked [this](http://stackoverflow.com/questions/13349204/manipulate-input-file-stream) [question](http://stackoverflow.com/questions/13349610/c-how-to-overload-cin-to-read-file) [four times](http://stackoverflow.com/questions/13351455/c-what-is-own-input-manipulator) now. Maybe you should step back and program something simpler until you get more familiar with the basics? – Kerrek SB Nov 13 '12 at 05:05
  • I've actually seen it for the first time, but it seems the first part (mapping strings to class names) is a duplicate of http://stackoverflow.com/questions/582331/is-there-a-way-to-instantiate-objects-from-a-string-holding-their-class-name, and the second part (heterogenous container) is a duplicate of http://stackoverflow.com/questions/4738405/how-can-i-store-objects-of-differing-types-in-a-c-container. – jogojapan Nov 13 '12 at 05:06
  • Use a vector, a set would be wrong because a set can't store duplicates. – john Nov 13 '12 at 07:07

0 Answers0