Jump to content
  • Advertisement
Sign in to follow this  
Frizbe

Classes

This topic is 3975 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 am having trouble setting up my classes for some reason. this is my class as it stands now: class code { public: void SDL_Init(); }; When I compile this I get this error: error C2011: 'code' : 'class' type redefinition I am using Visual Studio 2005. I am fairly sure I have everything in the correct order, but keep getting this error. Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
Change the name of the class from 'code' to something else. 'Code' is a pretty generic name, and it looks like it was previously defined, perhaps in one of your header files.

Share this post


Link to post
Share on other sites
Did you make sure to use include guards?

inside each header file:

#ifndef __HEADER_1_INCLUDED__ // use a unique constant here for each header file
#define __HEADER_1_INCLUDED__

// put header file content here

#endif // __HEADER_1_INCLUDED__

more details here:

http://www.gamedev.net/reference/programming/features/orgfiles/

Share this post


Link to post
Share on other sites
Quote:
Original post by AIDev
Change the name of the class from 'code' to something else. 'Code' is a pretty generic name, and it looks like it was previously defined, perhaps in one of your header files.

I have tried a few different names and nothing changes. I am still trying to just get the classes set up before i try anything else now.

Quote:
Original post by fpsgamer
Did you make sure to use include guards?

inside each header file:

#ifndef __HEADER_1_INCLUDED__ // use a unique constant here for each header file
#define __HEADER_1_INCLUDED__

// put header file content here

#endif // __HEADER_1_INCLUDED__

more details here:

http://www.gamedev.net/reference/programming/features/orgfiles/


I have no idea what you are talking about. Kinda sucks I have looked at some stuff online and in my C++ for Dummies books and everything I have read says I have it set up right.

And this error is coming up on code that worked 6 months ago. Which is why I belive it is a setting in VS, but alas I can't figure out which setting it is.

Share this post


Link to post
Share on other sites
Quote:
Original post by Frizbe
I have no idea what you are talking about. Kinda sucks I have looked at some stuff online and in my C++ for Dummies books and everything I have read says I have it set up right.


At this point we can't say for sure what is wrong without seeing your code. But I still suspect it is the include guard problem.

As a general practice, ALL header files should have include guards anyways. The fact that your C++ text neglected to mention that is a bit worrisome.

Share this post


Link to post
Share on other sites
Quote:
Original post by fpsgamer
Quote:
Original post by Frizbe
I have no idea what you are talking about. Kinda sucks I have looked at some stuff online and in my C++ for Dummies books and everything I have read says I have it set up right.


At this point we can't say for sure what is wrong without seeing your code. But I still suspect it is the include guard problem.

As a general practice, ALL header files should have include guards anyways. The fact that your C++ text neglected to mention that is a bit worrisome.


This is my entire header as it stands now because I keep getting this error:

#include <iostream>
#include <string.h>
#include "SDL/SDL.h"
using namespace std;

class code
{
public:
void SDL_Init();
};

Share this post


Link to post
Share on other sites
Quote:
Original post by Frizbe
This is my entire header as it stands now because I keep getting this error:

#include <iostream>
#include <string.h>
#include "SDL/SDL.h"
using namespace std;

class code
{
public:
void SDL_Init();
};


It would be helpful if we could also see your source files.

Share this post


Link to post
Share on other sites
Quote:
Original post by fpsgamer
Quote:
Original post by Frizbe
This is my entire header as it stands now because I keep getting this error:

#include <iostream>
#include <string.h>
#include "SDL/SDL.h"
using namespace std;

class code
{
public:
void SDL_Init();
};


It would be helpful if we could also see your source files.

As in IOStream, String.h and SDL.h?
Sorry for the beginner-esque questions I am still trying to a handle on the terminology.

Share this post


Link to post
Share on other sites
Quote:
Original post by Frizbe
Quote:
Original post by fpsgamer
Quote:
Original post by Frizbe
I have no idea what you are talking about. Kinda sucks I have looked at some stuff online and in my C++ for Dummies books and everything I have read says I have it set up right.


At this point we can't say for sure what is wrong without seeing your code. But I still suspect it is the include guard problem.

As a general practice, ALL header files should have include guards anyways. The fact that your C++ text neglected to mention that is a bit worrisome.


This is my entire header as it stands now because I keep getting this error:

#include <iostream>
#include <string.h>
#include "SDL/SDL.h"
using namespace std;

class code
{
public:
void SDL_Init();
};


Like previous posters have said, you're missing include guards. Obligatory link for more information.

EDIT: Whoops, you've already been linked. But the point is, you still need them. The point of include guards is to prevent your compiler from "reading" your header file more than once. C++ doesn't allow multiple definitions of the same named thing, so if you #include your header files in more than one place without the appropiate guards, you'll hit the redefinition error.

EDIT2: I should stop skimming so quickly. fpsgamer has explained exactly what you need to do in this post

EDIT3: And do read the article! It's important :P

Share this post


Link to post
Share on other sites
Quote:
Original post by Frizbe
Quote:
Original post by fpsgamer
Quote:
Original post by Frizbe
This is my entire header as it stands now because I keep getting this error:

#include <iostream>
#include <string.h>
#include "SDL/SDL.h"
using namespace std;

class code
{
public:
void SDL_Init();
};


It would be helpful if we could also see your source files.

As in IOStream, String.h and SDL.h?
Sorry for the beginner-esque questions I am still trying to a handle on the terminology.


Header files: Your files that end in .h
Source files: Your files that end in .c or .cpp

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!