I am looking for a way to create a new instance of a class when a function is called, but still have access to the object inside other functions.
I thought about creating an instance of the class inside main() and writing over it from within a function, but it does not seem to do anything when the code is run.
This code is to imagine what I want accomplish.
#include <iostream>
class Account {
private:
int a;
public:
int b;
};
void createAccount(){
// i want to create a class instance under certain conditions (function
//invoked)
Account myAccount();
};
void getAccountInt(){
//and access the newly created instance here in some way
std::cout << myAccount.b << endl;
};
int main(){
return 0;
}
I'm bad at asking these types of things, this is the best example i could come up with.