I have two files, main.ccp and namespace.cpp (Not the actual names, but for simplification)
My namespace.cpp can be boiled down to the following:
#pragma once
namespace MyNamespace {
int A = 0;
}
And my main.cpp basically just uses the content of MyNamespace:
#include "namespace.cpp"
int main() {
...
// Using MyNamespace::A
...
}
But I keep getting a LNK2005 error in MyNamespace.obj, that A is already defined in main.obj.
Which is weird: It's not like I've defined it twice. I'm literally just using it in my main file, but since I wanted to clean up my main file a little bit I put it into it's own file and into a namespace.
I don't understand where the problem is, would appreciate help. Thanks