Sign in to follow this  

expected unqualified id before string constant

This topic is 3317 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been trying to figure out what's wrong with compiling my program. I think I've narrowed it down to a few lines that might be the problem, however I still have no idea what's wrong. I'm passing all of the right parameters into the functions, but it give the error "expected unqualified id before string constant" and shows me a line in math.h aka <cmath> Anyways, I think that this is the problem function. player.getX() and getY() return floats
void Enemy::fireShot1(float velocity)
{
    float xVelocity = sqrt(fabs((velocity * velocity) - (player.getX() * player.getX())));
    float yVelocity = sqrt(fabs((velocity * velocity) - (player.getY() * player.getY())));

    createShot1(xPos, yPos, xVelocity, yVelocity, sprite);
}

Just out of curiosity, is it faster to do (variable * variable) or pow(variable, 2)?

Share this post


Link to post
Share on other sites
Quote:
Original post by SomeoneX
I've been trying to figure out what's wrong with compiling my program. I think I've narrowed it down to a few lines that might be the problem...

The code you pasted is unrelated to the error message in your thread topic. If that's your compiler's error output, it includes a line number on which the error occurred. Share that. Also, if possible, just share the whole file.

Quote:
Just out of curiosity, is it faster to do (variable * variable) or pow(variable, 2)?

It's premature optimization. But (variable * variable) is faster.

Share this post


Link to post
Share on other sites
Well I'm pretty sure it's an error in my code.
The actual error line is in math.h, which is <cmath> so I doubt that's the actual problem, but the part it's complaining about is:

math.h

#ifndef _MATH_H
#define _MATH_H 1

#include <features.h>

__BEGIN_DECLS //<<------ THIS LINE

/* Get machine-dependent HUGE_VAL value (returned on overflow).
On all IEEE754 machines, this is +Infinity. */

#include <bits/huge_val.h>
#ifdef __USE_ISOC99
# include <bits/huge_valf.h>
# include <bits/huge_vall.h>



So it might be one of the things I used <cmath> for.

The only other function that uses it is this, however, which also seems OK.


double distance(int x1, int y1, int x2, int y2)
{
return sqrt(pow(x2 - x1, 2) + pow(x2 - x1, 2));
}

Share this post


Link to post
Share on other sites
Well this is rather embarrassing, after a bit of Google assisted searching I tried a few solutions. Turns out I forgot a semicolon after a class definition... woops.
Thanks for all of the help, though.

Share this post


Link to post
Share on other sites

This topic is 3317 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this