0

私は MVS 2013 を使用しており、ファイル ListStruct.h に構造体を書きました。リンク中にエラー LNK2005 が発生します。

error LNK2005: "public: __thiscall ListStruct::ListStruct(void)" (??0ListStruct@@QAE@XZ) already defined in projekt1.obj

現在 - ListStruct.h の一部

#ifndef _LISTSTRUCT_H_
#define _LISTSTRUCT_H_

#include "stdafx.h"

struct ListStruct{
    Member *head;                       //wskaznik na poczatek listy
    Member *tail;                       //wskaznik na koniec listy
    void AddMember(int value);
    void RemoveMember(int value);
    void Display();
    ListStruct();
};
#endif

私のメインの一部:

#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
    ListStruct *base = new ListStruct;
    system("pause");
    return 0;
}

私は何を間違っていますか?ListStruct.cpp ファイルを作成する必要がありますか? どのように見えるはずですか?

4

1 に答える 1

0

It seems that in header ListStruct.h in the part that you did not show there is a definition of constructor

ListStruct();

As this header is included in more than one module then the linker issues error that the constructor is already defined.

Either you should define the constructor only in one module or define it with function specifier inline in the header.

于 2015-03-22T14:53:42.433 に答える