Error C2011 using classes

Feb 26, 2011 at 7:45pm
This is my header file

#ifndef H_extPersonType
#define H_extpersonType
# include <iostream>
# include <string>

using namespace std;

class extPersonType
{
public:

void printPerson() const;
//Function to print: First Name, Last Name.

void setName(string first, string last);
//Function to set the full name.
//Postcondition string first name, string last name.

string getFirst() const;
//Function to return the first name.

string getLast() const;
//fucntion to return the last name.

extPersonType(string first="", string last="");
//constructor to initialize the variables.

private:
//Variables to store data.
string firstName;//First Name.
string lastName;//Last Name.
};
#endif

And I am still gettin the error C2011. I thought that using the;

#ifndef
#define

Will fix it, but it's not doing it. Any help please???
Feb 26, 2011 at 7:50pm
closed account (zb0S216C)
What is the full error?
Feb 26, 2011 at 10:58pm
The full error is probably something like this -> http://msdn.microsoft.com/en-us/library/sksadsda.aspx
Obviously, the error is not located in this header. Could we see some more code?
Feb 27, 2011 at 12:08am
1>g:\lbcc\c12\martinezassig3\martinezassig3\extpersontype.h(19): error C2011: 'extPersonType' : 'class' type redefinition


Thats the full error, and that is the whole code for that header file
Feb 27, 2011 at 2:23am
closed account (zb0S216C)
How many source files include this header?
Feb 27, 2011 at 9:23pm
I suppose none, because I'm using the header for my class, and a cpp file for the operations of my class, and then I have another cpp file for main program.
Feb 27, 2011 at 10:21pm
closed account (zb0S216C)
It's clear that the error doesn't live within the header file itself. Can you post both source files?
Feb 27, 2011 at 10:31pm
As an aside, putting using namespace std; at global scope in a header file is generally considered bad form, as anyone who ever includes that header file will have using namespace std; at the global scope level of their code and they won't even know it.
Last edited on Feb 27, 2011 at 10:36pm
Mar 3, 2011 at 10:59pm
Cool, I looked at my other source files, and I took out extPersonType.h and it worked fine. What I dont understand is if I take out the using namespace std, my program wont work. Why is that???
Mar 3, 2011 at 11:03pm
Because you use std::strings. If you don't write using namespace std; at the top of your program, you will have to put std:: before everything that is in the std namespace.
Topic archived. No new replies allowed.