C++ How to read a string of text and create object of their class

Posted by user1777711 on Stack Overflow See other posts from Stack Overflow or by user1777711
Published on 2012-11-13T04:58:18Z Indexed on 2012/11/13 4:59 UTC
Read the original article Hit count: 251

Filed under:

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.!

© Stack Overflow or respective owner

Related posts about c++