Ok, so what I want to do is this:
/* main.cpp */
#include <iostream>
#include "lol.h"
using namespace std;
int main(/*blah blah*/)
{
lawl(5);
cout << rofl.lmao;
}
/* lol.cpp */
#include "lol.h"
void lawl(int lol)
{
rofl.lmao = lol;
}
/* lol.h */
struct kekeke
{
int lmao;
}
kekeke rofl;
void lawl(int);
This will compile but not link* as it generates an error about declaring
rofl
twice (since lol.h is included in both lol.cpp and main.cpp).
I've tried to check up on this and found some tips on enclosing the globally included header in
#ifndef .. #endif
to make sure that it is only compiled once. This does not seem to help, however.
Is there a way to do this, or do I have to use some kind of workaround?
*using gcc