How do I use variables that are in my main file (main.cpp
) in other files (foo.h
, foo.cpp
)?
No code is really necessary but I'll post some to help clarify my question.
main.cpp
#include<iostream>
#include<foo.h>
using namespace std;
int aa = 10;
int bb = 20;
Foo xyz;
int main() {
cout<<"Hello World"<<endl;
xyz.doSomething();
return 0;
}
foo.h
#ifndef FOO_H
#define FOO_H
class Foo
{
public:
void doSomething() {
int abc = aa + bb;
cout<<"aa + bb = "<<abc<<endl;
};
};
#endif // FOO_H