fungso
fungso

Reputation: 13

error C2011 and defined

I have search for error 2011 I found error C2011: '' : 'class' type redefinition, and I definitely got #ifndef and #define in my c++ code.

Here is my code

//Member.h
#ifndef MEMBER_H
#define MEMBER_H

#include <string>
using namespace std;

class member
{
private:
    int id;
    string name;
    char sex;
    int age;
public:
    void addMember();
    void setName(string n);
    void setSex(char s);
    void setAge(int a);
};
#endif

.

//Member.cpp
#include <string>
#include "Member.h"
using namespace std;

class member
{
private:
    int id;
    string name;
    char sex;
    int age;
public:
    void addMember()
    {
        void setName(string n);
        void setSex(char s);
        void setAge(int a);
        //relationship
    }
    void setName(string n) { name = n; }
    void setSex(char s) { sex = s; }
    void setAge(int a) { age = a; }
};

It gives me the same error C2011. Please help

Upvotes: 0

Views: 255

Answers (1)

Puppy
Puppy

Reputation: 147036

You have clearly defined the class member twice- once in the header file and once in the C++ file, exactly like the compiler told you was the problem.

Upvotes: 1

Related Questions