First of all I know this isnt "correct." However, I like to test things out and I have run into this problem that if I create a global variable in the header file and declare it extern in the main.cpp file, I can use it(Note that I did not include the class header on this example). However, if I actually try to do the same thing, the only difference being including the class header, I get an error.
(error: ld returned 1 exit status).
I wonder why this happens?
Code as requested:
Main.cpp:
#include <iostream>
#include "albino.h"
using namespace std;
extern int iVar;
int main()
{
cout << iVar << endl;
}
albino.h:
#ifndef ALBINO_H
#define ALBINO_H
int iVar = 10;
class albino
{
public:
albino();
};
#endif // ALBINO_H
The albino.cpp doesnt have anything.
ERROR: ||error: ld returned 1 exit status|