Here's some code to give you an idea.
Code:
#include <iostream>
using namespace std;
class Critter
{
public:
int year;
};
void CreateCritter()
{
Critter *crit = new Critter;
cout << "You just created a critter!" << endl << endl;
crit->year = 5;
}
int main()
{
int choice;
do
{
cout << "0: Quit" << endl;
cout << "1: Create Critter" << endl;
cout << "2. Find out age" << endl;
cout << "3. Release your critter back into the wild"
cout << "Choice: ";
cin >> choice;
switch (choice)
{
case 0:
cout << "Goodbye!" << endl;
break;
case 1:
cout << endl;
CreateCritter();
break;
case 2:
cout << endl;
GetAge();
case 3:
DeleteCritter();
default:
cout << endl;
cout << "Sorry, but " << choice << " is not a valid choice!" << endl << endl;
}
} while (choice != 0);
return 0;
}
Is there way to create an object of a class during runtime through a function, and be able to display the critter's age through a function without any scope issues during compile time?