C++: Assign value to global class variable

Viewed 93

Consider the class MyClass that has no default constructor.

I want to write a code that looks like the following:

MyClass instance;

void init_system() {
    instance = MyClass(parameters, of, the, constructor);
}

The code I wrote above of course fails with the error MyClass has no C'tor that takes no arguments.

Is there any correct way to do it, or I must implement a workaround, e.g. using shared pointers?

3 Answers
Related