c++ - 错误 C2011 和定义

标签 c++

我搜索错误 2011 我找到了 error C2011: '' : 'class' type redefinition ,而且我的 C++ 代码中肯定有 #ifndef 和 #define。

这是我的代码

//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; }
};

它给了我同样的错误 C2011。请帮忙

最佳答案

您已经明确定义类 member 两次 - 一次在头文件中,一次在 C++ 文件中,就像编译器告诉您的问题一样。

关于c++ - 错误 C2011 和定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27087287/

相关文章:

c++ - 如果在 C++ 中的 malloc() 之后调用 free() 会出错

c++ - 使用 boost::timer 作为定期调用的类的成员时,类销毁时出现段错误

c++ - 如何使用 WGS84 Datum 将 C 中的 UTM 坐标转换为纬度/经度?

c++ - C++多线程错误: no matching function for call to 'std::thread::thread(<unresolved overloaded function type>

c++ - 当一个基类指针指向一个基类对象时,编译器是否会使用动态绑定(bind)?

c++ - 使用 std::rand() 在 C++ 中进行硬币翻转实验,结果不正确

c++ - 如何处理遗留代码中的方法名称重复

c++ - 更改一个类属性的数据类型会导致在构造子类对象期间出现段错误

c++ - 在 pytorch c++ API 中添加填充

c++ - 一个数组中的消息和变量名 C++