[C++] 'Error: An anonymous union cannot have function members'

Started by
4 comments, last by deadstar 15 years, 10 months ago
Hi all, I'm trying to battle an error that GCC throws up, on what seems like pretty trivial code:

#ifndef SYM_SPRITE
#define SYM_SPRITE

#include "SYM_3DMaths.h"
#include "SYM_Texture.h"

namespace SYM
{
    class SYM_SPRITE
    {
        public:
            //Constructor
            SYM_SPRITE();

            //Load texture
            bool Load(string Filename);

            //Render sprite
            void Render();

            //Transformation
            void SetPosition(SYM_VECTOR3 Pos);
            void SetRotation(SYM_VECTOR3 Rot);
            void SetScale(SYM_VECTOR3 Scl);

            SYM_VECTOR3 GetPosition();
            SYM_VECTOR3 GetRotation();
            SYM_VECTOR3 GetSize();

            //Colour
            void SetTransparency(float Trans);

        private:
            //Texture
            SYM_TEXTURE *Texture;

            //Transformation
            SYM_VECTOR3 Position;
            SYM_VECTOR3 Rotation;
            SYM_VECTOR3 Size;
    };

} //namespace

#endif // SYM_SPRITE

The error:

/home/matt/storage/development/cvg3/codebase/symmetry/SYM_Sprite.h|10|error: an anonymous union cannot have function members|
Line 10, the { before 'public:'. It seems fine to me.

"The right, man, in the wrong, place, can make all the dif-fer-rence in the world..." - GMan, Half-Life 2

A blog of my SEGA Megadrive development adventures: http://www.bigevilcorporation.co.uk

Advertisement
Your class has the same name as your #define a few lines above... Don't forget a preprocessor define is replaced "stupidly" like a copy/paste.

Change the name of the class, or the define's.
English is not my native language.Sam.
The #define SYM_SPRITE is the problem since your class is also called SYM_SPRITE. The preprocessor will replace every occurance of SYM_SPRITE with whatever it's defined as, which is nothing in your case, turning your code into:
namespace SYM{    class    {        public:            //Constructor            ();            //Load texture            bool Load(string Filename);            /* etc.. */    }} //namespace
-LuctusIn the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move - Douglas Adams
Ahhh of course, my mistake.

I've just switched to Code::Blocks and it did that for me, I'm used to typing them in myself: __SYM_SPRITE.

Thank you all.

"The right, man, in the wrong, place, can make all the dif-fer-rence in the world..." - GMan, Half-Life 2

A blog of my SEGA Megadrive development adventures: http://www.bigevilcorporation.co.uk

1. Given that the classes in question appear to reside in the SYM namespace, what exactly is the point of the SYM_ prefix?

2. AFAIK it's fairly atypical to use all caps for class names (and using mixed case would provide another means of avoiding clashes with similarly named macros).
Quote:Original post by jyk
1. Given that the classes in question appear to reside in the SYM namespace, what exactly is the point of the SYM_ prefix?


It's a habit I need to kick myself out of. I used SYM_ prefix before someone on here mentioned namespaces, so I stuck namespaces in and intended to remove all the prefixes, but never got round to it. I create new classes with SYM_ out of habit...

Quote:Original post by jyk
2. AFAIK it's fairly atypical to use all caps for class names (and using mixed case would provide another means of avoiding clashes with similarly named macros).


Blame Microsoft for this one, I started C++ by learning about WIN32 and DirectX 6, all class names are in uppercase.

I'm gonna tidy the whole engine up as soon as I've met a few deadlines. Thanks for the hints :)

"The right, man, in the wrong, place, can make all the dif-fer-rence in the world..." - GMan, Half-Life 2

A blog of my SEGA Megadrive development adventures: http://www.bigevilcorporation.co.uk

This topic is closed to new replies.

Advertisement