I can't figure out this error

Started by
4 comments, last by Chad Smith 17 years, 6 months ago
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.
Advertisement
Try this..


armor.h
#include <iostream>#include <string>using namespace std;class armor{    string name;    int armorRating;};
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.
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.
DOH! How could I forget the inclusion guards?! Thanks
Yes, I would think it is the lack of inclusion guards. That is what it seems like the error is saying.

Chad.

This topic is closed to new replies.

Advertisement