Jump to content
  • Advertisement
Sign in to follow this  
Cable_pair

I can't figure out this error

This topic is 4319 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'm getting an error in programming a simple text based rpg in VC++. Here's the code that has the error:
// armor.h

#include <string>

struct armor
{
	std::string name;
	int armorRating;
};




And here's the error i'm getting:
1>c:\documents and settings\ian\my documents\visual studio 2005\projects\rpg_1\rpg_1\armor.h(6) : error C2011: 'armor' : 'struct' type redefinition
1>        c:\documents and settings\ian\my documents\visual studio 2005\projects\rpg_1\rpg_1\armor.h(6) : see declaration of 'armor'


Any help would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Try this..


armor.h

#include <iostream>
#include <string>

using namespace std;

class armor
{
string name;

int armorRating;
};


Share this post


Link to post
Share on other sites
Try adding header guards, i.e.:


// armor.h

#ifndef ARMOR_H
#define ARMOR_H

#include <string>

struct armor
{
std::string name;
int armorRating;
};

#endif // #ifndef ARMOR_H


I'm guessing this will solve the problem.

Be sure to do this for your other header files as well.

Share this post


Link to post
Share on other sites
Quote:
Original post by nooblet
Try this..


armor.h
*** Source Snippet Removed ***
It's generally considered bad form to put 'using' declarations in header files, as it pollutes the files that include the header.

In any case, I don't think that's the solution to the OP's problem. Your example actually doesn't change anything, other than including <iostream> unnecessarily and changing armor's default privilages.

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.

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!