I'm using MVS 2013 and I wrote struct in file ListStruct.h. During linking I'm getting error LNK2005:
error LNK2005: "public: __thiscall ListStruct::ListStruct(void)" (??0ListStruct@@QAE@XZ) already defined in projekt1.obj
Now - part of 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
Part of my main:
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
ListStruct *base = new ListStruct;
system("pause");
return 0;
}
What am I doing wrong? Do I have to create ListStruct.cpp file? How it supposed to look like?
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.