im searching the internet for about half an hour because of a (actually basic and simple) problem in C++. Maybe im missing something, but I don't know what. Lets say, i have 3 files: "main.cpp", "dosomething.cpp" and "Header.h".
"Header.h":
#pragma once
#ifndef HEADER_H
#define HEADER_H
char text[] = "This is a text";
#endif // !HEADER_H
"main.cpp"
#include <stdio.h>
#include <iostream>
#include "Header.h"
using namespace std;
void main() {
cout << text << endl;
}
and "dosomething.cpp"
#include "Header.h"
void dosth() {
}
Now the compiler/linker tells me that "text" is already defined in another file. Why? I know how guard idioms such as #pragma once and #ifndef etc. work - atleast I think so. I have no idea whats wrong here. The code itself works (when not including the header in "dosomething.cpp").
Any idea?
Edit: Im using Visual Studio 2015