#include <iostream>
#include <string>
class test {
public:
int random_number = 2;
};
int main () {
test t1;
t1.random_number = 3;
std::cout << t1.random_number << std::endl;
}
How would I access the object t1 from another file?
For example test.cpp / test.h
Normally, you wouldn't. They are in different Translation Units (TU)
To create an object of type test include the test.hpp file. The class has functions which can take arguments of different types, so for example if a class foo wanted to do something with a test object, then one of its functions would accept a test as a parameter.
This raises a whole lot of questions, I suggest you read up a bit.
You created t1 in main. ideally you want to have a separate file for each class including main. Then in your main file you will include all the other files (classes) and create the objects in main NOT in another file and try to bring it over. Hope this helps!