Declaring Class function error?
Hi all, :)
I am experiencing a strange problem when declaring classes outside the main source file in VC++. I have made an experiment that demonstrates my problem. There are two files: “main.cpp” and “class.cpp”.
“main.cpp” content:
Code:
#include "class.cpp"
int main() {
return 0;
}
“class.cpp” content:
Code:
class Class {
public:
void Test();
};
void Class::Test() {
return;
}
When I try to compile I get following error:
--------------------Configuration: main - Win32 Debug--------------------
Compiling...
main.cpp
class.cpp
Linking...
class.obj : error LNK2005: "public: void __thiscall Class::Test(void)" (?Test@Class@@QAEXXZ) already defined in main.obj
Debug/main.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
main.exe - 2 error(s), 0 warning(s)
It says that the function void Test() is already declared, but how? Please help me, am I doing something wrong? :(