Prev: sorting a vector
Next: Lunch
From: Chris on
I keep getting this error from my compiler: "parse error before ')'
token"

Here is the insulting code block.

void draw(playpen & pp) {
shape s;
bool i(true);
do{
point2d const point(read<point2d>("Enter a point: "));
if (point.x() > 9998) i = false;
s.push_back(point);
}while(i);

hue const shade(read<hue>("What colour? "));
//drawshape(pp, s, hue);
}

The problem line has been commented out (drawshape(pp, s, hue);). I'm
not sure what is wrong. I have spent over an hour checking the code in
a decent text editor and found no missing brackets. Every line has a
semicolon. Here is the complete file:

#include "art_menu2.h"
#include "fgw_text.h"
#include "point2d.h"
#include "shape.h"

#include <iostream>

using namespace std;
using namespace fgw;

namespace { //open an unnamed namespace

string const choices("CDFMPS");
enum art_menu_choices {
clear_am = 'C',
draw_am = 'D',
finish_am = 'F',
plotmode_am = 'M',
scale_am = 'S',
plot_am = 'P'
};

void clear_playpen(playpen & pp){
hue const new_colour(read<int>("What background colour? "));
pp.clear(new_colour);
pp.display();
}

void change_scale(playpen & pp){
int const new_scale(read<int>("What is the new scale? "));
pp.scale(new_scale);
}

void change_plotmode(playpen & pp){
cout << "\t\tWhich Plotmode do you want?\n";
cout << "\tD for direct mode.\n";
cout << "\tF for filter mode.\n";
cout << "\tA for additive mode.\n";
cout << "\tJ for disjoint mode.\n";
char const new_mode(cin.get());
switch(toupper(new_mode)){
case 'D':
pp.setplotmode(direct);
break;
case 'F':
pp.setplotmode(filter);
break;
case 'A':
pp.setplotmode(additive);
break;
case 'J':
pp.setplotmode(disjoint);
break;
default:
cout << "***Invalid response ignored.***\n";
}
}

void plot_pixel(playpen & pp){
int const x(read<int>("What x value? "));
int const y(read<int>("What y value? "));
hue const shade(read<hue>("What colour? "));
pp.plot(x, y, shade);
pp.display();
}

void draw(playpen & pp) {
shape s;
bool i(true);
do{
point2d const point(read<point2d>("Enter a point: "));
if (point.x() > 9998) i = false;
s.push_back(point);
}while(i);

hue const shade(read<hue>("What colour? "));
drawshape(pp, s, hue);
}
}

void display_choices(){
cout << "Select one of the following by pressing the\n"
<< "key indicated and then pressing the return key.\n\n";
cout << "\tC Clear the Playpen Window.\n"
<< "\tM Change the plotting mode.\n"
<< "\tS Change the scale.\n"
<< "\tP Plot a pixel.\n"
<< "\tF Finish. \n\n";
}

char get_choice(){
// string const choices("CFMPS"); has been removed from here
// and moved adjacent to the definition of enum art_menu_choices.
cout << "Action: (Press letter followed by Return): ";
do{
string input;
getdata(cin, input);
char const letter(toupper(input[0]));
int const choice(choices.find(letter));
//Check that choice is valid
if(choice < choices.size()){
return letter;
}
// Note you can only get here if the choice was not valid.
cout << '"' << letter << '"'<< "is not an option.\n";
cout << "Please try again: ";
} while(true);
}

bool do_choice(char choice, playpen & pp){
bool more(true);
switch(choice){
case clear_am:
clear_playpen(pp);
break;
case draw_am:
draw(pp);
case finish_am:
more = false;
break;
case plotmode_am:
change_plotmode(pp);
break;
case plot_am:
plot_pixel(pp);
break;
case scale_am:
change_scale(pp);
break;
default: throw problem("Not a valid option");
}
return more;

The code is answer to Task 21 in Chapter 8 of "You Can Do It!" by
Francis Glassborow. I'm sure I'm missing something really simple,
which makes my problem even more frustrating.

From: R. Scott Mellow on

"Chris" wrote
>I keep getting this error from my compiler: "parse error before ')'
> token"
>
> Here is the insulting code block.
>
> void draw(playpen & pp) {
> shape s;
> bool i(true);
> do{
> point2d const point(read<point2d>("Enter a point: "));
> if (point.x() > 9998) i = false;
> s.push_back(point);
> }while(i);
>
> hue const shade(read<hue>("What colour? "));
> //drawshape(pp, s, hue);
> }

Try:

drawshape(pp, s, shade);

The error message can be misleading but it isn't saying that you're missing
a parenthesis, it's saying it can't parse what comes before it. In other
words, it can't pass a type name as a parameter, it expects an object of
that type, presumably.

--
Randy



From: Bart van Ingen Schenau on
R. Scott Mellow wrote:

>
> "Chris" wrote
>>I keep getting this error from my compiler: "parse error before ')'
>> token"
>>
<snip>
> The error message can be misleading but it isn't saying that you're
> missing a parenthesis, it's saying it can't parse what comes before
> it.
>
In general, when the compiler reports an error message like 'parse
error' or 'syntax error', then the compiler really tries to tell you:
"What you have written here is so utterly confusing for me that I can't
make any sense out of it."

This situation will most often occur when you are missing an essential
bracket, parenthesis or semi-colon, but that is certainly not the only
way to confuse a compiler, as the code from the OP showed.

Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/
 | 
Pages: 1
Prev: sorting a vector
Next: Lunch