Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


class declaration/typedef

This topic is 5462 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 made a class, but it won''t compile. Uint16 is defined in SDL.h, which was included earlier, so it isn''t the problem. I think it might be the typedef, but I''m not sure.

typedef Uint16 u16;  (error:  syntax error before '';'' token)

typedef struct {
  u16 x,y;           (error:  parse error before '';'' token)
} xypair;

class Character {
    Character(u16,u16,const char *);  (error:  parse error before '';'' token)
    void Blit(void);
    void SetPos(u16,u16);  (''u16'' was not declared in this scope)
                           (''u16'' was not declared in this scope)
                           (invalid data member initialization)
                           (use ''='' to init...)
    void SetSprite(u16);
    void SetFrame(u16);
    bool valid;
    xypair pos;
    u16 sprite,frame;
    SDL_Surface *surface;

Sorry, it''s probably some dumb thing I forgot. Thank you.

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
it looks like Uint16 isn''t a defined type. But if you have included SDL before this line and SDL has this type, then everything should work fine.

However, why not just use this:

typedef unsigned short u16;

Share this post

Link to post
Share on other sites
Thanks, I figured out the problem, but now I have another. My code is arranged as follows:

#inc SDL
#inc def
#inc char

included in that order

Main can use anything defined in any of them, but def doesn''t understand a type defined in SDL. Also, a type defined in def can''t be used in char. It seems like the compiler (Dev-C++/mingw) is compiling them separately then attaching the object files. Is there some way (hopefully not makefiles) to tell the compiler that char needs def?

Share this post

Link to post
Share on other sites
Header files are not ''compiled separately''. When you write #include "foo", the C preprocessor literally substitute that line with the contents of the file. Your main.cpp file is therefore constituted of all the code in SDL, followed by all the code in def, followed by all the code in char.

Which means that, when compiling main.cpp, everything that was in previously included header files is visible to later header files - and to code in main.cpp.

So long as you have included def before char in *all* your source files, you shouldn''t get errors (unless you messed up the code in the headers, of course).

Makefiles have nothing to do with that, and solve a completely different problem (recompiling only what is necessary when you have modified source/header files).

[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post

Link to post
Share on other sites

  • 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!