I'm learning C++.
I want to declare a variable without creating an instance of it.
MyClass variable;
// More code
int main(int argc, char **argv)
{
// More code
variable = MyClass(0);
// More code
}
If I do that, and MyClass only has a constructor declared MyClass::MyClass(int value) it fails.
I need to make it global because I'm going to use it on a CallBack function and I can pass that variable as a parameter.
And also, I don't want to create an instance of the class when I declare the variable and then, another instance when I use the constructor. I think I'm wasting resources and CPU time.
Is it possible to declare a variable without instance it?
initfunction? Or maybestd::optionalcould be a... hm... option.MyClass* variable = NULL.