strange "syntax error" problem :S

This is a discussion on strange "syntax error" problem :S within the C++ Programming forums, part of the General Programming Boards category; hey again, I know I'm asking a load of questions, but I find this problem really strange :S I use ...

  1. #1
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717

    strange "syntax error" problem :S

    hey again, I know I'm asking a load of questions, but I find this problem really strange :S
    I use Visual C++ 2008 Express, and i get this error "error C2061: syntax error : identifier 'platform'" Yes I've tried google

    ok, so I got this function:

    Code:
    void character::stop(HGE* hge, character& c, platform& plat){
    	float dt = hge->Timer_GetDelta();
    
    	if(c.charRect.Intersect(&plat.rect)){
    		if(dir == LEFT) x += speed * dt;
    		if(dir == RIGHT) x -= speed * dt;
    		if(dir == DOWN) y -= gravityPull;
    		if(dir == UP) y += speed * dt;
    	}
    }
    And one other that's kinda the same, just in a different class

    Code:
    void worldManager::chrIntersectPlat(character& c, platform& plat){
    	c.stop(hge,c,plat);
    
    }
    See, those look kinda the same, just that the first one has also the 'HGE* hge' argument... But the first one gives the error :S
    Both have 'platform.h' included, why does it then only work on one of them?
    Thanks in advance!
    Last edited by Akkernight; 02-22-2009 at 09:40 AM.
    Currently research OpenGL

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    Perhaps character isn't what you think it is.
    If it's a macro, it could have turned your code into pudding before you know what's happened.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    what's that supposed to mean? o.O
    Currently research OpenGL

  4. #4
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    Make sure you haven't defined any macros that could be causing 'character' or 'c' to be preprocessed away.

  5. #5
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    what's a macro o.O?
    Currently research OpenGL

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Akkernight View Post
    what's a macro o.O?
    Cynical answer: Something you almost certainly shouldn't be using in C++.

    Real answer: Something defined using the #define preprocessor directive.

  7. #7
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    ohh... Well, I havn't used #define, except for the h files, like #define CHARACTER_H and such stuff xP
    oh and I have one enum, but it doesn't have any name close to any of those :S
    Currently research OpenGL

  8. #8
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    How is platform defined?

  9. #9
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    Code:
    #define PLATFORM_H
    This is very frusterating xP
    Currently research OpenGL

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    That is clearly not a definition of the platform datatype.

  11. #11
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    huh o.O? That's what I'm having in the platform.h file...
    Code:
    #ifndef PLATFORM_H
    #define PLATFORM_H
    
    #include "hge.h"
    #include "hgerect.h"
    #include "character.h"
    
    //platform.h
    
    class platform {
    
    private:
    	hgeQuad platQuad;
    
    public:
    	platform();
    	virtual ~platform();
    
    	float z;
    	float x, y;
    	hgeRect rect;
    
    	void updateQVert();
    	void updateRect();
    	void quadRender(HGE* hge);
    	void quadTexture( HTEXTURE tex, DWORD col, int blend);
    	void move(float x2, float y2);
    };
    
    #endif
    Code:
    #ifndef CHARACTER_H
    #define CHARACTER_H
    
    //character.h
    #include "hge.h"
    #include "hgerect.h"
    #include "console.h"
    #include "platform.h"
    
    class character {
    	
    protected:
    	void renderQuad(HGE* hge, hgeQuad* quad);
    	void flipLeft(hgeQuad* quad);
    	void flipRight(hgeQuad* quad);
    	void updateQVert(hgeQuad* quad);
    
    public:
    	character();
    	virtual ~character();
    
    	enum direction {LEFT, RIGHT, DOWN, UP};
    	direction dir;
    
    	virtual void pullDown();
    	virtual void stop(HGE* hge, character& c, platform& plat);
    
    	float speed;
    	float x, y;
    	float z;
    	float gravityPull;
    	hgeRect charRect;
    	
    };
    #endif
    That might help?
    Currently research OpenGL

  12. #12
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So then, when someone asks for the definition of platform, you should give them the definition of platform:
    Code:
    class platform {
    
    private:
    	hgeQuad platQuad;
    
    public:
    	platform();
    	virtual ~platform();
    
    	float z;
    	float x, y;
    	hgeRect rect;
    
    	void updateQVert();
    	void updateRect();
    	void quadRender(HGE* hge);
    	void quadTexture( HTEXTURE tex, DWORD col, int blend);
    	void move(float x2, float y2);
    };
    Notice how this is the code that defines platform as a new type, specifically a class, with all the appropriate members.

    Both of these functions also need #include <character.h> as well, it looks like. (And just as a wild guess, you need to include the headers before you do the functions, but you've probably got that.) If you have both the headers, then you don't get any errors.

  13. #13
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    huh o.O? So I'm supposed to include 'platform.h' in platform.h and 'character.h' in character.h o.O?
    Well, I tried that and it didn't work...
    Or did you mean something else?
    Currently research OpenGL

  14. #14
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    Not that this will solve your problem but:
    Code:
    void character::stop(HGE* hge, character& c, platform& plat){
    	float dt = hge->Timer_GetDelta();
    
    	if(c.charRect.Intersect(&plat.rect)){
    		if(dir == LEFT) x += speed * dt;
    		if(dir == RIGHT) x -= speed * dt;
    		if(dir == DOWN) y -= gravityPull;
    		if(dir == UP) y += speed * dt;
    	}
    }
    Are you sure you mean "&plat.rect"? Since plat is passed as a reference "&plat" literally means "the address of plat"

  15. #15
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    yeah well, before I did that it gave me an compiler error :S
    Currently research OpenGL

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange problem with GETLINE
    By wco5002 in forum C++ Programming
    Replies: 13
    Last Post: 07-07-2008, 09:57 AM
  2. Strange problem
    By G4B3 in forum C Programming
    Replies: 6
    Last Post: 05-14-2008, 02:07 PM
  3. Strange problem with classes in header files
    By samGwilliam in forum C++ Programming
    Replies: 2
    Last Post: 02-29-2008, 03:55 AM
  4. Strange problem
    By ~Kyo~ in forum Game Programming
    Replies: 0
    Last Post: 02-14-2006, 09:35 PM
  5. Strange problem with fts_open call
    By jhopper in forum C Programming
    Replies: 0
    Last Post: 02-25-2002, 11:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21