Expression errors

So, there is this specific line, and whenever the compiler (dev C++) reachs it, it throws these 2 errors:
177 C:\...\Object.h functional cast expression list treated as compound expression 176 C:\...\Object.h expected primary-expression before "int"

The lines codes (they are all actually one, but segmented because the line was too long):

1
2
3
4
5
6
spritegrid* a(/*1*/string(frameline.substr(0, frameline.find(","))), 
                                                /*2*/int(frameline.substr(frameline.find(",")+1,frameline.find(",", frameline.find(",")+1)).c_str()), 
                                                /*3*/int(frameline.substr(frameline.find(",", frameline.find(",")+1)+1,  frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)).c_str()), 
                                                /*4*/int(frameline.substr( frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)+1, frameline.find(",", frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)+1)).c_str()), 
                                   /*line 176*/ /*5*/int(frameline.substr(frameline.find(",", frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)+1)+1, frameline.find(",", (frameline.find(",", frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)+1)+1)).c_str()), 
                                   /*line 177*/ /*6*/frameline.substr(frameline.rfind(',')));   


Additional/Extra info:
The line is call of class of a type. The line extracts 6 parameters separated by a comma "," from a txt file and returns the parameters into a class constructor of paratypes:
spritegrid (string, int, int, int, int, string);
Line 4: watch your parentheses
I checked; can't see any unpaired one. Can you please be more specific?
There has got to be an easier way of doing that - you have 22 calls to find to produce 6 pieces of information?

Even successive calls to find would be much easier than that nightmare.

Investigate using a stringstream.

Hope all goes well.
That line is a nightmare to figure out. You'll find it easier to fix the problem, and to maintain it in general, if you break it down into smaller statements, e.g.

1
2
3
4
5
6
7
8
string arg1 = frameline.substr(0, frameline.find(","));
int arg2 = frameline.substr(frameline.find(",")+1,frameline.find(",", frameline.find(",")+1)).c_str();
int arg3 = ...;
int arg4 = ...;
int arg5 = ...;
int arg6 = ...;

spritegrid* a(arg1, arg2, arg3, arg4, arg5, arg6);   

Using sensible, self-documenting names for those variables, of course.
Last edited on
Hmph, OK I will try. I've got this problem with being neat when writing any code. I am always like "For this project, imma make my code super neat", *fast forward* => http://i33.servimg.com/u/f33/16/27/78/35/screen10.png
Ok so now, I tried breaking up the code as Mikey has suggested, and I managed to fix the "functional cast expression error". Now the compiler howls at the following line:
1
2
3
int    spgdarg3 = int(frameline.substr( frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)+1, frameline.find(",", frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)+1)).c_str());

/*THIS LINE*/ int    spgdarg4 = int(frameline.substr(frameline.find(",", frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)+1)+1, frameline.find(",", (frameline.find(",", frameline.find(",", frameline.find(",", frameline.find(",")+1)+1)+1)+1)).c_str());

saying: expected primary-expression before "int"
and: expected `,' or `;' before "int"

What the hell am I doing wrong? I can't see anything wrong with my declaration nor with my "punctuation" (parenthesis, semicolons..etc).
Last edited on
I see a mismatch in parentheses in the second of those lines - one more open parenthesis than close.

Seriously, there has to be a simpler way to express this stuff. It's going to be a nightmare making this work, and making it work right, when your lines are so long and complex it's hard to see whether you've even closed all your parentheses. That line has eight nested parentheses at one point!
You don't seem to understand what we are trying to say - you still have a nightmare function call.

Check out the stringstream documentation :

http://www.cplusplus.com/reference/sstream/stringstream/
http://www.cplusplus.com/reference/istream/istream/get/


get has an option to read up to a delimiting character - make use of this to get the individual strings you are after.

Do this with a loop, or multiple statements - don't try to combine it all into one monster function call.

Make use of the good function as an end condition, put the 6 strings into a vector.

Hope this helps



It really did help in fact! Thanks y'all!
Topic archived. No new replies allowed.