Conflict with a class and SDL_mixer

Hello everybody,

I am creating a simple program in C++ to testing SDL_mixer. I have a simple
class called “ngl_sound”. In this moment the class is empty. Only
constructor and destructor:

class ngl_sound {
public:
ngl_sound(void);
~ngl_sound(void);
};

nothing more at this moment.

When I compile, I have this error:

NGL_Sound.h:1: error: using typedef-name ?ngl_sound? after ?class?
/usr/include/SDL/SDL_mixer.h:129: error: ?ngl_sound? has a previous
declaration here

In this moment, I see the line 129 in SDL_mixer.h:
typedef struct _Mix_Music Mix_Music;

“ngl_sound” not appears in SDL_mixer.h file

?Any idea?. Thanks.

I might be overlooking the obvious, but it doesn’t seem immediately apparent what the problem is.

Do you get the same error no matter what you name the class? That is, if you name it (e.g.) ‘some_random_name’ rather than ‘ngl_sound’, do you get exactly the same error?

Also, if you could post a complete, minimal example (which presumably would include only the necessary includes, the class definition that you posted, and the main() function), that would probably help.

It looks like maybe it’s being included more than once - try doing a:

#ifndef _NGL_SOUND
#define _NGL_SOUND

// Implement class prototype

#endif /* _NGL_SOUND */

If that a try.
-OzOn Sun, Feb 20, 2011 at 5:43 AM, Altair Linux wrote:

Hello everybody,

I am creating a simple program in C++ to testing SDL_mixer. I have a simple
class called “ngl_sound”. In this moment the class is empty. Only
constructor and destructor:

class ngl_sound {
??? public:
??? ngl_sound(void);
??? ~ngl_sound(void);
};

nothing more at this moment.

When I compile, I have this error:

NGL_Sound.h:1: error: using typedef-name ?ngl_sound? after ?class?
/usr/include/SDL/SDL_mixer.h:129: error: ?ngl_sound? has a previous
declaration here

In this moment, I see the line 129 in SDL_mixer.h:
typedef struct _Mix_Music Mix_Music;

“ngl_sound” not appears in SDL_mixer.h file

?Any idea?. Thanks.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hello everybody,

I am creating a simple program in C++ to testing SDL_mixer. I have a simple class called “ngl_sound”. In this moment the class is empty. Only constructor and destructor:

class ngl_sound {
public:
ngl_sound(void);
~ngl_sound(void);
};

nothing more at this moment.

Your code is invalid, this is probably causing the C++ parser to get confused.

The correct syntax is:

class ngl_cound {
public:
ngl_sound(); // default constructor
~ngl_sound(); // destructor
};

void arguments are not permitted in C++.
Lack of an argument means “no arguments”.

Contrast to C, where lack of an argument means “no type information,
arbitrary arguments” and the void argument is required to mean
"no argument".On 20/02/2011, at 9:43 PM, Altair Linux wrote:


john skaller
@john_skaller

Since when?

Please have a look at section 8.3 of the C++ standard.–
Paulo

On Sun, Feb 20, 2011 at 2:46 PM, john skaller <skaller at users.sourceforge.net wrote:

On 20/02/2011, at 9:43 PM, Altair Linux wrote:

Hello everybody,

I am creating a simple program in C++ to testing SDL_mixer. I have a
simple class called “ngl_sound”. In this moment the class is empty. Only
constructor and destructor:

class ngl_sound {
public:
ngl_sound(void);
~ngl_sound(void);
};

nothing more at this moment.

Your code is invalid, this is probably causing the C++ parser to get
confused.

The correct syntax is:

class ngl_cound {
public:
ngl_sound(); // default constructor
~ngl_sound(); // destructor
};

void arguments are not permitted in C++.
Lack of an argument means “no arguments”.

Contrast to C, where lack of an argument means “no type information,
arbitrary arguments” and the void argument is required to mean
"no argument".


john skaller
skaller at users.sourceforge.net


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

john skaller wrote:

void arguments are not permitted in C++.

Using ‘void’ in this way is perfectly legal (if not necessarily idiomatic) in C++. (The OP’s code compiles cleanly with both GCC and VC++.)

Since when?

Please have a look at section 8.3 of the C++ standard.

Ok, I accept you’re right since you have a copy of it and I don’t :slight_smile:

This doesn’t work with my version of g++:

void f(void); // works
typedef void A;
void f(A); // fails

So actually I’m right, you cannot use a void type as an argument.
Using the keyword “void” here is a special hack. Don’t do it.

The parsing of constructors and destructors is extremely difficult,
there’s no reason to confuse things by using C compatibility hacks
in C++ only code.

If this doesn’t explain the OP’s problem, I see nothing else wrong:
the diagnostic is clearly nonsense, so GIGO: something else
must be wrong (parsing looked like a candidate :)On 21/02/2011, at 1:04 AM, Paulo Pinto wrote:


john skaller
@john_skaller

So actually I’m right, you cannot use a void type as an argument.

You’re confusing using ‘void’ as an argument type with using the ‘void’ keyword to indicate an empty argument list. The latter is perfectly legal in C++, and it’s the latter that’s under discussion here.

Quote:
So actually I’m right, you cannot use a void type as an argument.

You’re confusing using ‘void’ as an argument type with using the ‘void’ keyword to indicate an empty argument list. The latter is perfectly legal in C++, and it’s the latter that’s under discussion here.

As noted before I concede the point. But it’s bad style.
I was took quick in my reply, which was based on a visual pattern match …
obviously based on my own usage.

And we’re not helping the OP so lets look for something else?On 21/02/2011, at 1:52 AM, Jesse A. wrote:


john skaller
@john_skaller

There’s a simple and easy way to prevent most name collision errors in
C++: put all of your code in its own namespace. Just two extra lines in
each of your files, and you’ll never have to worry about name collision
between your code and an external library ever again.On 2/20/2011 03:43, Altair Linux wrote:

When I compile, I have this error:

NGL_Sound.h:1: error: using typedef-name ?ngl_sound? after ?class?
/usr/include/SDL/SDL_mixer.h:129: error: ?ngl_sound? has a previous
declaration here


Rainer Deyke - rainerd at eldwood.com

I delete “void” in constructor and destructor. No work.
I put 3 empty lines and the end of the source file. No work.
I not find the section 8.3 of the C++ standard. ?Is it in
http://www.cplusplus.com ?

Please provide the full code you are trying to compile.

Just the class is not enough for us to give proper advices.

The C++ Standard is a document that you have to buy from you local ANSI/ISO
institute. Is it used by anyone that wants to know how the language is
specified,
but mostly compiler vendors.

You can get a draft version here,
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf--
Paulo

On Mon, Feb 21, 2011 at 8:31 AM, Altair Linux wrote:

I delete “void” in constructor and destructor. No work.
I put 3 empty lines and the end of the source file. No work.
I not find the section 8.3 of the C++ standard. ?Is it in
http://www.cplusplus.com ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Altair Linux wrote:

I delete “void” in constructor and destructor. No work.
I put 3 empty lines and the end of the source file. No work.

The use of ‘void’ in this context is not the problem. As Paulo Pinto mentioned, we really need to see a complete, minimal example. If you can reduce it to a file that contains only (for example):

  1. The inclusion of the SDL_mixer header
  2. Your class definition
  3. A main() function

It should be easier to spot the error.

If in the process of creating such an example the error disappears, that’ll give you a hint as to where the problem actually is (e.g. a multiple inclusion as suggested earlier).

I suspect your include guards (or some other preprocessor statement) might
be causing this. Another possible cause is an incorrect forward declaration
or typedef that ends up being included before the SDL_Mixer stuff. You might
get some insight by viewing the preprocessed source files - there is usually
a flag you can pass your compiler to see this information. Warning: this is
often very verbose!

This is why using the preprocessor for anything other than conditional
compilation is frowned upon in C++ (where there are alternatives). You are
looking at the source of SDL_Mixer.h line 127, but the compiler is seeing
the preprocessed version and it could be very different…

If using gcc you can give the option -E to see how the preprocessed code
looks like.On Mon, Feb 21, 2011 at 10:36 AM, Brian Barrett <brian.ripoff at gmail.com>wrote:

I suspect your include guards (or some other preprocessor statement) might
be causing this. Another possible cause is an incorrect forward declaration
or typedef that ends up being included before the SDL_Mixer stuff. You might
get some insight by viewing the preprocessed source files - there is usually
a flag you can pass your compiler to see this information. Warning: this is
often very verbose!

This is why using the preprocessor for anything other than conditional
compilation is frowned upon in C++ (where there are alternatives). You are
looking at the source of SDL_Mixer.h line 127, but the compiler is seeing
the preprocessed version and it could be very different…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I send the code http://www.megaupload.com/?d=18S8CHVB

NGL is a library, uses C/C++ and SDL and some other library (SDL_image,
SDL_gfx, etc). A easy way to make 2D games.

This is only a BETA, some parts are incomplete.

Sorry, I send the last post incomplete.

“Test.cpp” file are the source file.

“Compile” file contains the gcc line needed for link all.

When I compile Test.cpp, I have this error:

In file included from Nautilus.h:54,
from Test.cpp:1:
NGL_Sound.h:7: error: using typedef-name ?ngl_sound? after ?class?
/usr/include/SDL/SDL_mixer.h:129: error: ?ngl_sound? has a previous
declaration here

This is my first “serius” project :slight_smile: I am not a expert in C/C++ or SDL, but
for me this is a very interesting project.

Although someone may check out your project, you might have better luck getting help if you were to create a minimal example that generates the error, as suggested previously. This is generally a fairly effective debugging method, as it usually has one of two outcomes: a) during the process of reducing the code to a minimal example you find the cause of the problem, or b) you end up with an example that’s concise enough to post to a forum such as this one, which makes it easier for people to help.

(In the meantime though, be sure to check and make sure you’re using header guards and so forth correctly, as mentioned previously.)

The file Test.cpp is a minimal example

Can you post the contents of that file here? (In other words, use ‘code’ tags and just paste it into a post).