Hello,
Here is my example code:
// Main.h
#ifndef MAIN_H
#define MAIN_H
#include <iostream>
using namespace std;
#include <string.h>
string HelloWorld = "Hello World!\n";
void HelloEarth();
#endif
// Main.cpp
#include "Main.h"
int main()
{
cout << HelloWorld;
HelloEarth();
}
// Secondary.cpp
#include "Main.h"
void HelloEarth()
{
cout << HelloWorld;
}
Problem is, it appears the #ifndef
and #define
tags aren't stopping Secondary.cpp from redeclaring HelloWorld.
When I attempt to compile and run, the IDE (in my case Code::Blocks) opens up a file called "locale_facets.tcc" and shows an error on line 2497.
This is the message I get for the error:
obj\Debug\Main.o||In function `ZSt17__verify_groupingPKcjRKSs':|
C:\Program Files (x86)\CodeBlocks\bin\..\lib\gcc\mingw32\3.4.4\..\..\..\..\include\c++\3.4.4\bits\locale_facets.tcc|2497|multiple definition of `HelloWorld'|
obj\Debug\Secondary.o:C:\Program Files (x86)\CodeBlocks\bin\..\lib\gcc\mingw32\3.4.4\..\..\..\..\include\c++\3.4.4\bits\locale_facets.tcc|2497|first defined here|
||=== Build finished: 2 errors, 0 warnings ===|
Does anyone know what I did wrong?