Indirection in class member declaration
Hi;
In the C++ code fragment below I would like to declare plotter as being either if type XPlotter or GIFPlotter depending on the value of "plot" Code:
... this is what I get in compiling: Quote:
( not unlikely ) or I've badly misunderstood the syntax here. Thanks for any assistance Jeff |
What is the function signature of the function plotter? Also, you declare and define char* myplotter. What is the purpose of this variable?
|
Quote:
When you declare a variable you have to give an actual type. Putting the name of a variable which holds a string won't work because the string isn't there during compile time. If you want to decide the type of plotter at compile time you can probably do so with macros, but that probably isn't what you want. The proper way of doing this is to define a Plotter class that is a superclass of XPlotter and GIFPlotter and declare plotter as a pointer to type Plotter. A pointer of a superclass may point to an object of any of its subclasses. |
Re: Plotter
Hi
these are from Gnu's plotutils package specifically the plotter class ( c++ plotting library ) from <plotter.h> Quote:
"XPlotter" "GIFPlotter" the end of which is to convey on (my line 68) Code:
XPlotter plotter(cin,cout,cerr,params); to output to the screen or to a file. Jeff |
re: Plotter class
ntubski:
yes- but it is a plotter class ( see above ) Quote:
|
Quote:
Code:
<TYPE_NAME> <VAR_NAME>; Code:
"GIFPlotter" plotter Quote:
Quote:
All you have to do is declare plotter as a Pointer to Plotter: Code:
... |
Re: *plotter
Ntubski - Thanks I'll try that, this is actually closer to my
initial efforts, but I kept loosing scope from my function being declared inside the conditional. The pointer should address that. I think parts of the Plotutils doc are somewhat out of date the listing of the constructors in my reply to mark jones is copied right out of the header file. I've been using the plotutils code for XPlotter for a couple of years. but have had to write separate programs to view or save to file . This iteration I'm trying to consolidate the code, and hopefully increase my skills on o-o syntax. Thanks for the assist. Jeff |
You want to first declare plotter as a pointer to the base class
Code:
Plotter *plotter; Code:
if(!strcmp(plot,"X")) |
Quote:
Quote:
Quote:
|
All times are GMT -5. The time now is 06:40 PM. |