D
David Goodyear
At the moment im experimenting with ideas in C++ and would really like to
solve the following, please please help.
Sorry i dont even know what the subject is this would come under?
Sorry if this is elsewhere in the newsgroup & please reply with links to
threads or something? (I dont know what to look for )
(Terms are prob. all wrong as well )
The problem:
I have a data structure represented by a class. Use a date class as an
example i guess.
I have a GUI that the user can output the data to, or a file it can be
formatted and cout used to output it.
There are thousands of these date objects that need to be output, to some
form of output device.
The output device is chosen at run-time and hence the class that will be
used to format the data, from the date objects
and output it.
A class may be a GUI, File, etc...
Is there anyway I could write some base class / interface in C++, that when
classes inherit the interface class
certain methods would have to be written?. I.E. all classes must have a
function that is void Output_Short_Date?
I'm not sure where to start on this bit even? Any pointers?
The idea was to instant the appropiate class and then do function pointers
before the loop, so that one line in the code, would send
the date to the correct output.
Just to give idea - syntax is of course all out without editor to hand
switch (userChoice) {
case GUI:
//set outputDateFormatter to GUIFormatter
break;
case FILE:
//set outputDateFormatter to FileFormatter
break;
}
loop {
*outputDateFormatter (dateObject localDate);
}
would go to the correct instance of the outputter, and display the date.
The alternative is to use conditional checks but obviously these would slow
down the loops by quite a bit the higher the number of times they were
executed.
Any suggestions on what i can look up to do the above idea, (if your really
bored examples would be fantastic. My main problem is Im not sure how you
can use Templates in C++ to do this, function pointers, or what other
relevant stuff may help do this easily.
Anyway thanks for reading and any help would be great
Happy XMAS all.
solve the following, please please help.
Sorry i dont even know what the subject is this would come under?
Sorry if this is elsewhere in the newsgroup & please reply with links to
threads or something? (I dont know what to look for )
(Terms are prob. all wrong as well )
The problem:
I have a data structure represented by a class. Use a date class as an
example i guess.
I have a GUI that the user can output the data to, or a file it can be
formatted and cout used to output it.
There are thousands of these date objects that need to be output, to some
form of output device.
The output device is chosen at run-time and hence the class that will be
used to format the data, from the date objects
and output it.
A class may be a GUI, File, etc...
Is there anyway I could write some base class / interface in C++, that when
classes inherit the interface class
certain methods would have to be written?. I.E. all classes must have a
function that is void Output_Short_Date?
I'm not sure where to start on this bit even? Any pointers?
The idea was to instant the appropiate class and then do function pointers
before the loop, so that one line in the code, would send
the date to the correct output.
Just to give idea - syntax is of course all out without editor to hand
switch (userChoice) {
case GUI:
//set outputDateFormatter to GUIFormatter
break;
case FILE:
//set outputDateFormatter to FileFormatter
break;
}
loop {
*outputDateFormatter (dateObject localDate);
}
would go to the correct instance of the outputter, and display the date.
The alternative is to use conditional checks but obviously these would slow
down the loops by quite a bit the higher the number of times they were
executed.
Any suggestions on what i can look up to do the above idea, (if your really
bored examples would be fantastic. My main problem is Im not sure how you
can use Templates in C++ to do this, function pointers, or what other
relevant stuff may help do this easily.
Anyway thanks for reading and any help would be great
Happy XMAS all.