[SOLVED] Nested #include seems to be causing errors with C++

[SOLVED] Nested #include seems to be causing errors with C++
0

I’ve been trying to figure this out for hours, would someone tell me what is wrong?

I am getting all these errors when I try to #include one of the header file. This header file was included else where and it was fine. (Which rules out legitimate syntax errors.) However, when I try to include it in to this particular header file, it returns these errors:

> Error    1    error C2143: syntax error : missing ';' before '*' (..\Classes\Prisoner.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    11    1    PrisonBreak
> Error    2    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\Prisoner.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    11    1    PrisonBreak
> Error    3    error C2143: syntax error : missing ';' before '*' (..\Classes\Prisoner.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    15    1    PrisonBreak
> Error    4    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\Prisoner.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    15    1    PrisonBreak
> Error    5    error C2143: syntax error : missing ';' before '*' (..\Classes\Prisoner.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    16    1    PrisonBreak
> Error    6    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\Prisoner.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    16    1    PrisonBreak
> Error    7    error C2143: syntax error : missing ';' before '*' (..\Classes\Prisoner.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    17    1    PrisonBreak
> Error    8    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\Prisoner.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    17    1    PrisonBreak
> Error    9    error C2061: syntax error : identifier 'Point' (..\Classes\Prisoner.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    35    1    PrisonBreak
> Error    10    error C2146: syntax error : missing ';' before identifier 'tileCoordForPosition' (..\Classes\Prisoner.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    39    1    PrisonBreak
> Error    11    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\Prisoner.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    39    1    PrisonBreak
> Error    12    error C2061: syntax error : identifier 'Point' (..\Classes\Prisoner.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    39    1    PrisonBreak
> Error    14    error C2061: syntax error : identifier 'Point' (..\Classes\Prisoner.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    41    1    PrisonBreak
> Error    18    error C2143: syntax error : missing ';' before '*' (..\Classes\Officer.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    11    1    PrisonBreak
> Error    19    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\Officer.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    11    1    PrisonBreak
> Error    20    error C2143: syntax error : missing ';' before '*' (..\Classes\Officer.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    15    1    PrisonBreak
> Error    21    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\Officer.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    15    1    PrisonBreak
> Error    22    error C2143: syntax error : missing ';' before '*' (..\Classes\Officer.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    16    1    PrisonBreak
> Error    23    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\Officer.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    16    1    PrisonBreak
> Error    24    error C2143: syntax error : missing ';' before '*' (..\Classes\Officer.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    17    1    PrisonBreak
> Error    25    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\Officer.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    17    1    PrisonBreak
> Error    26    error C2061: syntax error : identifier 'Point' (..\Classes\Officer.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    35    1    PrisonBreak
> Error    27    error C2146: syntax error : missing ';' before identifier 'tileCoordForPosition' (..\Classes\Officer.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    39    1    PrisonBreak
> Error    28    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\Officer.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    39    1    PrisonBreak
> Error    29    error C2061: syntax error : identifier 'Point' (..\Classes\Officer.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    39    1    PrisonBreak
> Error    31    error C2061: syntax error : identifier 'Point' (..\Classes\Officer.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    41    1    PrisonBreak
> Error    35    error C2143: syntax error : missing ';' before '*' (..\Classes\Player.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    11    1    PrisonBreak
> Error    36    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\Player.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    11    1    PrisonBreak
> Error    37    error C2143: syntax error : missing ';' before '*' (..\Classes\People.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    11    1    PrisonBreak
> Error    38    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\People.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    11    1    PrisonBreak
> Error    39    error C2143: syntax error : missing ';' before '*' (..\Classes\Player.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    15    1    PrisonBreak
> Error    40    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\Player.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    15    1    PrisonBreak
> Error    41    error C2143: syntax error : missing ';' before '*' (..\Classes\People.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    15    1    PrisonBreak
> Error    42    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\People.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    15    1    PrisonBreak
> Error    43    error C2143: syntax error : missing ';' before '*' (..\Classes\Player.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    16    1    PrisonBreak
> Error    44    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\Player.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    16    1    PrisonBreak
> Error    45    error C2143: syntax error : missing ';' before '*' (..\Classes\People.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    16    1    PrisonBreak
> Error    46    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\People.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    16    1    PrisonBreak
> Error    47    error C2143: syntax error : missing ';' before '*' (..\Classes\Player.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    17    1    PrisonBreak
> Error    48    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\Player.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    17    1    PrisonBreak
> Error    49    error C2143: syntax error : missing ';' before '*' (..\Classes\People.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    17    1    PrisonBreak
> Error    50    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\People.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    17    1    PrisonBreak
> Error    51    error C2061: syntax error : identifier 'Point' (..\Classes\Player.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    35    1    PrisonBreak
> Error    52    error C2146: syntax error : missing ';' before identifier 'tileCoordForPosition' (..\Classes\Player.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    39    1    PrisonBreak
> Error    53    error C2061: syntax error : identifier 'Point' (..\Classes\People.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    35    1    PrisonBreak
> Error    54    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\Player.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    39    1    PrisonBreak
> Error    55    error C2146: syntax error : missing ';' before identifier 'tileCoordForPosition' (..\Classes\People.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    39    1    PrisonBreak
> Error    56    error C2061: syntax error : identifier 'Point' (..\Classes\Player.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    39    1    PrisonBreak
> Error    57    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\People.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    39    1    PrisonBreak
> Error    59    error C2061: syntax error : identifier 'Point' (..\Classes\People.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    39    1    PrisonBreak
> Error    61    error C2061: syntax error : identifier 'Point' (..\Classes\Player.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    41    1    PrisonBreak
> Error    64    error C2061: syntax error : identifier 'Point' (..\Classes\People.cpp)    f:\documents\apps\prisonbreak\classes\playscene.h    41    1    PrisonBreak
> Error    74    error C2660: 'PlayScene::OcupiedSpace' : function does not take 1 arguments    f:\documents\apps\prisonbreak\classes\player.cpp    56    1    PrisonBreak
> Error    75    error C2660: 'PlayScene::OcupiedSpace' : function does not take 1 arguments    f:\documents\apps\prisonbreak\classes\player.cpp    57    1    PrisonBreak
> Error    76    error C2660: 'PlayScene::OcupiedSpace' : function does not take 1 arguments    f:\documents\apps\prisonbreak\classes\player.cpp    64    1    PrisonBreak
> Error    78    error C2660: 'PlayScene::OcupiedSpace' : function does not take 1 arguments    f:\documents\apps\prisonbreak\classes\player.cpp    65    1    PrisonBreak
> Error    79    error C2660: 'PlayScene::OcupiedSpace' : function does not take 1 arguments    f:\documents\apps\prisonbreak\classes\player.cpp    72    1    PrisonBreak
> Error    80    error C2660: 'PlayScene::OcupiedSpace' : function does not take 1 arguments    f:\documents\apps\prisonbreak\classes\player.cpp    73    1    PrisonBreak
> Error    81    error C2660: 'PlayScene::OcupiedSpace' : function does not take 1 arguments    f:\documents\apps\prisonbreak\classes\player.cpp    81    1    PrisonBreak
> Error    82    error C2660: 'PlayScene::OcupiedSpace' : function does not take 1 arguments    f:\documents\apps\prisonbreak\classes\player.cpp    82    1    PrisonBreak
> Error    83    error C2660: 'PlayScene::setViewPointCenter' : function does not take 1 arguments    f:\documents\apps\prisonbreak\classes\player.cpp    93    1    PrisonBreak

Worked: (All header files is guarded by #ifndef uniquename #define uniquename)

PlayScene.h

#include "cocos2d.h"
#include "Definition.h"
#include "People.h"

People.h

#include "cocos2d.h"

Player.h

#include "People.h"
#include "PlayScene.h"

and Player::People (The previous works fine)

but if #include PlayScene.h in People.h , it gives errors:

(DOESNT WORK)
People.h

#include "cocos2d.h"
#include "PlayScene.h"

PlayScene.h

#include "cocos2d.h"
#include "Definition.h"
#include "People.h"

try with:

in .h file

class People;
class PlayScene :public cocos2d::Layer
{

}

in playScene.cpp
#include “People.h”

and in peopele same thing for included files…

Thanks, I tried it, but it seems to return more syntax errors.

Type in google c++ forward declaration. It will help you to properly include headers where needed. Also try restarting XCode.

Thanks I solved the problem. I think it had to do with the #ifndef variable. Some of my variables starts with _.

I replaced all the ifndef with #progma once.

People.h

#pragma once
#include "cocos2d.h"
class PlayScene;

People.cpp

#include "People.h"
#include "Definition.h"
#include "PlayScene.h"

PlayScene.h

#pragma once

#include "People.h"
#include "cocos2d.h"
#include "Definition.h"

#include <stdio.h>
#include <stdlib.h>

/* Random number generator in [0, 1] */
#define Rand() ((double)rand()/RAND_MAX)

/* Structure of a particle */
typedef struct {
double *x;
double *v;
double f;
double pbest;
double *x_star;
double *NEW;
} ParticleRec, *Particle;

/*
Parameters for PSO
*/

/* Number of particles /
#define Nparticles 50
/
Maximum number of iterations /
#define T_MAX 1000
/
The value of inertia weight at t=0 (W_0) and t=T_MAX (W_T) /
#define W_0 0.9
#define W_T 0.4
#define MAX_V 2.0
/
The cognitive parameter (c1) and the social parameter (c2) */
#define c1 2.0
#define c2 2.0

/*
Definitions for a problem
*/

/* Number of variables: problem dependent */
#define Nvariables 5

/* Objective function for minimization: problem dependent */
#define better(y1, y2) (y1<y2)

/* The following is the function of Sum_i (x_i-1)^2 */
void Evaluate(Particle P)
{
int i;

P->f=0.0;
for(i=0; i<Nvariables; i++)
    P->f+=(P->x[i]-1)*(P->x[i]-1);

}

/* update pbest */
void UpdateBest(Particle P)
{
int j;

for(j=0; j<Nvariables; j++) P->x_star[j]=P->x[j];
P->pbest=P->f;

}

/* Initialization of particles: problem dependent /
/
The function returns the index of the best particle /
int Initialize(Particle P, int n)
{
int i, j;
int G; /
the index of the best particle */

G=0;
for(i=0; i<n; i++) {
    for(j=0; j<Nvariables; j++) {
        P[i].x[j]=Rand();    /* problem dependent */
        P[i].v[j]=0.0;        /* problem dependent */
    }
    Evaluate(&P[i]);
    UpdateBest(&P[i]);
    if(better(P[i].f, P[G].f)) G=i;
}
return G;

}

/*
Definitions for PSO
*/

/* allocate new data structures */
#define New(type, n, msg) (type *)NewCell(sizeof(type), n, msg)

void *NewCell(int size, int n, char *msg)
{
void *NEW;

if((NEW = malloc(size*n))==NULL) {
    fprintf(stderr, "Cannot allocate memory for %d %s\n", n, msg);
    exit(1);
}
return NEW;

}

/* allocate “n” new particles */
Particle NewParticles(int n)
{
int i;
Particle P;

P=New(ParticleRec, n, "particles");
for(i=0; i<n; i++) {
    P[i].x=New(double, Nvariables, "x");
    P[i].v=New(double, Nvariables, "v");
    P[i].x_star=New(double, Nvariables, "x*");
}
return P;

}

/* Print a particle */
void Print(Particle P)
{
int j;

for(j=0; j<Nvariables; j++)
    printf("%f ", P->x_star[j]);
printf(" = %g\n", P->pbest);

}

//int t,i,j;
/* Particle Swarm Optimization */
main()
{
int t, i, j;
Particle P;
int G;
double w;

P=NewParticles(Nparticles);
G=Initialize(P, Nparticles);
w=W_0;
for(t=1; t<=T_MAX; t++) {
    for(i=0; i<Nparticles; i++) {
        for(j=0; j<Nvariables; j++) {
            P[i].v[j]=w*P[i].v[j]
                    +c1*Rand()*(P[i].x_star[j]-P[i].x[j])
                    +c2*Rand()*(P[G].x_star[j]-P[i].x[j]);
            if(P[i].v[j]<-MAX_V)
                P[i].v[j]=-MAX_V;
            else if(P[i].v[j]>MAX_V)
                P[i].v[j]=MAX_V;
            P[i].x[j]+=P[i].v[j];
        }
        Evaluate(&P[i]);
        if(better(P[i].f, P[i].pbest)) {
            if(better(P[i].f, P[G].pbest)) G=i;
            UpdateBest(&P[i]);
        }
    }
    printf("%4d: ", t); Print(&P[G]);
    w-=(W_0-W_T)/T_MAX;
}

}

This is my code, when i run, i get this error… please help me><
1>c:\users\jenny\documents\visual studio 2012\projects\face detection 1\face detection 1\source.cpp(130): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int