0

b.cpp

#include"a.h"
#include"a.cpp"

int main(){}

a.cpp

#include"a.h"

a::a(): b(0) { }

a.h

#ifndef A
#define A
class a{
	int b;
	a();
};
#endif

Getting; "1>b.obj : error LNK2005: "private: __thiscall a::a(void)" (??0a@@AAE@XZ) already defined in a.obj" when trying to compile.

Using Visual Studio 2010, Windows 7 64bits

Wheres my mistake?

Tyvm for your anwsers.

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Ancient Dragon
0

My guess is that you have a project that contains both a.cpp and b.cpp, then you have included a.cpp in b.cpp. You can't do that. In b.cpp remove the line that includes a.cpp.

0

It works and compiles if I comment out " #include"a.cpp" " in b.cpp, tyvm.

I guess the IDE does all those kinds of inclusions, hence if I add mine it includes the file twice, right?

Edited by welp: n/a

0

You need to understand how the IDE works -- the project contains both a.cpp and b.cpp. The IDE calls the compiler for each of those *.cpp files, then links them together with other libraries to generate the *.exe file. That's one reason you should never include one *.cpp file in another.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.