Jump to content
  • Advertisement
Sign in to follow this  
Jarwulf

syntax error

This topic is 3243 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

hi, I keep getting a syntax error'}' pointing to this C++ line and I'm not sure what's up. (I'll fix the issue with the similar names later.) struct location raycast[8]= {{-60,-60}, {0,-60}, {60,-60},{-60,0},{60,0}, {-60,60},{0,60}, {60,60}}; Here is the immediate code around it.
class pathfinder
{
public:
vector<locations> openlocations;
vector<locations> closedlocations;
locations currentsquare,squarecandidate;
vector<location> uncoveredpath;
struct location raycast[8]= {{-60,-60}, {0,-60}, {60,-60},{-60,0},{60,0}, {-60,60},{0,60}, {60,60}};



sf::Sprite CircleRay;
int iraycast,needpath,plotcurrent,castray,closedcheck,opencheck,finalmove,newmove,rootswitch,movecandidate,matchedpoint,setfinal;
float distancebetweenpoints,secondGvalue,currentGvalue,riserunfactor,pursuefactor,xpursuemove,ypursuemove,distancebetweenx,distancebetweeny;
sf::Image CircleRayImage;




void InitializePathfinder()
{
     if  (!CircleRayImage.LoadFromFile("circleray.png"))
      {
        std::cerr << "Error : cannot load image.\n";
       // return EXIT_FAILURE;
      }

    CircleRay.SetImage(CircleRayImage);
}

Share this post


Link to post
Share on other sites
Advertisement
In C++, you must initialize class members in its constructor:


struct location { /* ... */ };

class Foobar
{
private:
int myInteger;
double myDobule;
int myArray[3];
location myLocations[2];

public:
Foobar() : myInteger( 5 ), myDouble( 1.23 ) // << Initializer list
// , myArray( { 1, 12, 123 } ) // << Unfortunately, C++ does not support array initializers
{
myArray[0] = 1;
myArray[1] = 12;
myArray[2] = 123;

myLocations[0] = { 1, 12 };
myLocations[1] = { 123, 1234 };

// Or you can get creative:
static const location defaultLocations[2] = {
{ 1, 12 },
{ 123, 1234 }
};

std::copy( defaultLocations, defaultLocations + 2, myLocations );
}
};




Share this post


Link to post
Share on other sites
Do you need to store a separate set of locations for each pathfinder instance, or can they share the same set of locations?

If they can share the same set of locations, make it static:


class pathfinder {
...
static location raycast[8]; // you don't need the 'struct' keyword here in C++, by the way
};

location pathfinder::raycast[8] = {{-60,-60}, {0,-60}, {60,-60},{-60,0},{60,0}, {-60,60},{0,60}, {60,60}};

Share this post


Link to post
Share on other sites
I got the same error now its pointing to

raycast[0] = {-60,-60};



class pathfinder
{
public:
vector<locations> openlocations;
vector<locations> closedlocations;
locations currentsquare,squarecandidate;
vector<location> uncoveredpath;
location raycast[8];

pathfinder::pathfinder()
{

raycast[0] = {-60,-60};
raycast[1] = {0,-60};

raycast[2] = {60,-60};
raycast[3] = {-60,0};

raycast[4] = {60,0};
raycast[5] = {-60,60};

raycast[6] ={0,60};
raycast[7] = {60,60};

}

sf::Sprite CircleRay;
int iraycast,needpath,plotcurrent,castray,closedcheck,opencheck,finalmove,newmove,rootswitch,movecandidate,matchedpoint,setfinal;
float distancebetweenpoints,secondGvalue,currentGvalue,riserunfactor,pursuefactor,xpursuemove,ypursuemove,distancebetweenx,distancebetweeny;
sf::Image CircleRayImage;



Share this post


Link to post
Share on other sites
You cannot assign to an array or struct using an aggregate initialiser. You can only initialise them. The C++ initialisation list syntax does not provide a mechanism for this.

One idea is to give your location type a constructor taking two arguments (in C++, a struct is almost identical to a class and may have constructors, among other things).

You might also consider creating a type (like a struct or class) to represent the raycast array. Once you encapsulate the array in a type, you can take advantage fot the fact that you are dealing with first class types, unlike arrays:

struct Raycast
{
Location locations[8];
};

Raycast make_raycast()
{
Raycast raycast = {
// array data here
};
return raycast;
}

class PathFinder
{
Raycast raycast;
public:
PathFinder()
:
raycast(make_raycast())
{
}
};


The above assumes that the data should be mutable. For constant data I would probably use Zahlman's method, albeit using the "const" keyword.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!