Click here to Skip to main content
15,920,053 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: copying vectors/lists Pin
Joaquín M López Muñoz30-Sep-04 9:06
Joaquín M López Muñoz30-Sep-04 9:06 
GeneralRe: copying vectors/lists Pin
mcsherry30-Sep-04 9:39
mcsherry30-Sep-04 9:39 
GeneralRe: copying vectors/lists Pin
Joaquín M López Muñoz30-Sep-04 10:21
Joaquín M López Muñoz30-Sep-04 10:21 
Generaledt1 problem in vc .net Pin
Michael Liu30-Sep-04 2:45
Michael Liu30-Sep-04 2:45 
GeneralRe: edt1 problem in vc .net Pin
Iain Clarke, Warrior Programmer30-Sep-04 5:10
Iain Clarke, Warrior Programmer30-Sep-04 5:10 
GeneralData transfer from one dialog to a property page. Pin
Rajesh_K_Sharma30-Sep-04 2:23
Rajesh_K_Sharma30-Sep-04 2:23 
GeneralRe: Data transfer from one dialog to a property page. Pin
David Crow30-Sep-04 5:08
David Crow30-Sep-04 5:08 
GeneralMaterializing derived classes Pin
Jerome Conus30-Sep-04 2:00
Jerome Conus30-Sep-04 2:00 
Hi !

I'm facing a problem and I'm sure you'll be able to help me !

In my app, I have a class which represents a path (meaning : a path you can follow to go from A to B). This class (Path) is made of any number of Segments, which can be straight or curved.

Thus, apart from the class 'Path', I created a base class called 'Segment' and two classes derived from 'Segment' : 'StraightSergment' and 'ArcSegment'.
The 'Path' class contains a list of 'Segment's.

I want to serialize a Path into a string. Thus, I have a method 'toString' which will in turn call, for each segment, their own 'toString' function. As 'Segment' is an abstract class, it will actually call either 'StraightSegment::toString' or 'ArcSegment::toString'. So far so good.

class Path
{
public:
	...
	string toString();
	void fromString(string Source);
	...

private:
	list_of_segments MyList;
};

class Segment
{
	virtual string toString() = 0;
	virtual void fromString(string Source) = 0;
};

class StraightSegment : public Segment
{
	string toString();
	void fromString(string Source);
};

class ArcSegment : public Segment
{
	string toString();
	void fromString(string Source);
};


I have a problem when I need to materialize a 'Path' from a string : Before calling 'fromString' function from either 'StraightSegment' or 'ArcSegment', I have to decide which kind of segment it is. Where should I do this ? In the 'Segment' base class ? The problem is that 'Segment' would have to know each classes derived from it. Should I do it into another class ? The problem then would be that the 'Path' class would have to know another class than just 'Segment'.

Well, what do you suggest me ? Which solution is the best ? Are there any better solutions ?

Thank you for your help !
Jerome
GeneralRe: Materializing derived classes Pin
Iain Clarke, Warrior Programmer30-Sep-04 4:48
Iain Clarke, Warrior Programmer30-Sep-04 4:48 
GeneralTo track an errors-messages Pin
Billar30-Sep-04 1:32
Billar30-Sep-04 1:32 
Generalstl iterators Pin
RChin30-Sep-04 1:21
RChin30-Sep-04 1:21 
GeneralRe: stl iterators Pin
RChin30-Sep-04 1:48
RChin30-Sep-04 1:48 
GeneralRe: stl iterators Pin
Iain Clarke, Warrior Programmer30-Sep-04 4:54
Iain Clarke, Warrior Programmer30-Sep-04 4:54 
GeneralRe: stl iterators Pin
Joaquín M López Muñoz30-Sep-04 9:10
Joaquín M López Muñoz30-Sep-04 9:10 
GeneralRe: stl iterators Pin
RChin30-Sep-04 23:20
RChin30-Sep-04 23:20 
GeneralAsserion failed Pin
30-Sep-04 0:22
suss30-Sep-04 0:22 
GeneralRe: Asserion failed Pin
22491730-Sep-04 1:08
22491730-Sep-04 1:08 
GeneralRe: Asserion failed Pin
David Crow30-Sep-04 5:48
David Crow30-Sep-04 5:48 
GeneralProvide an Interface to my Program Pin
sweep12329-Sep-04 22:55
sweep12329-Sep-04 22:55 
GeneralRe: Provide an Interface to my Program Pin
22491730-Sep-04 1:25
22491730-Sep-04 1:25 
GeneralArrow Keys Pin
Neelesh K J Jain29-Sep-04 21:09
Neelesh K J Jain29-Sep-04 21:09 
GeneralRe: Arrow Keys Pin
V.29-Sep-04 22:32
professionalV.29-Sep-04 22:32 
GeneralRe: Arrow Keys Pin
Neelesh K J Jain29-Sep-04 23:22
Neelesh K J Jain29-Sep-04 23:22 
GeneralRe: Arrow Keys Pin
V.30-Sep-04 1:33
professionalV.30-Sep-04 1:33 
GeneralRe: Arrow Keys Pin
David Crow30-Sep-04 5:50
David Crow30-Sep-04 5:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.