ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
g++ fractal.c++ -o fractal
fractal.c++: In function 'int main(int, char**)':
fractal.c++:68: error: expected `;' before 'plotter'
fractal.c++:68: warning: statement has no effect
I assume ( silly me ) that what I want here is some sort of indirection. but either I'm not setting up the pointers right
( not unlikely ) or I've badly misunderstood the syntax here.
I assume ( silly me ) that what I want here is some sort of indirection. but either I'm not setting up the pointers right
( not unlikely ) or I've badly misunderstood the syntax here.
Thanks for any assistance
Jeff
You've badly misunderstood the syntax and the difference between runtime strings vs compile time variables names.
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.
ntubski:
yes- but it is a plotter class ( see above )
Quote:
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.
this is what I was attempting however ineffectively
myplotter is a variable which will carry either the values of
"XPlotter" "GIFPlotter"
the end of which is to convey on (my line 68)
What I was trying to say in my first post is that you can't use a variable like that. The syntax for declaring a variable is
Code:
<TYPE_NAME> <VAR_NAME>;
neither of these can be substituted with an expression that returns a string. You have to put an actual type name and a variable name. If you could use a variable in this way you would have to write declarations with type names in quotes like this:
Code:
"GIFPlotter" plotter
But you don't write them like this because type names are not strings.
Quote:
Originally Posted by websinger
Hi
these are from Gnu's plotutils package specifically
the plotter class ( c++ plotting library )
from <plotter.h>
ntubski:
yes- but it is a plotter class ( see above )
Quote:
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.
this is what I was attempting however ineffectively
What I didn't realize until now, is that XPlotter and GIFPlotter are also plotutils classes. I thought they were your own which is why I was telling you that you should subclass Plotter.
All you have to do is declare plotter as a Pointer to Plotter:
Code:
...
Plotter *plotter; //declare 'plotter' here
if(!strcmp(plot,"X")){
//Instances of the XPlotter and XDrawablePlotter classes always ignore the output stream
//argument, since they write graphics to an X Display rather than to a stream.
plotter = new XPlotter(cin,NULL,cerr,params);
}
else{
FILE *gif_file;
gif_file = fopen("somefile.gif", "w");
//add some error checking here...
plotter = new GIFPlotter(cin,gif_file,cerr,params);
}
...
Note: I left params in both the constructors although according to the plotutils manual there is no such parameter.
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.
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.
Just make sure you delete the object after you finish otherwise you get a memory leak
Quote:
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.
Yeah, only the old manual was online, and I didn't feel like downloading the whole package...
Quote:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.