im curious if i can conditional create an instance of an object like this
1 2 3 4 5 6 7
if (something == something1)
{
Object object;
}
object.somethingelse();
then use the object functions
EDIT:
any suggestions about choosing a class then a way to create that object depending on what the person chose.
for example:
if the input is lets say "warrior"
then in the background the warrior object is initialized.
im trying to avoid initializing all possible classes in the background but only initialize what is picked
i do have warrior class derived from a character class
The object will only exist in the scope inside the if statement. Imagine if your statement was false. What then? You'd be trying to call a member function on a non-existent object.