This seens to be basic, but I need some help.
I have a sample class:
class myClass {
int a;
int b;
}
Then a factory:
class myFactory {
std::unique_ptr<myClass> getInstance()
{
return std::unique_ptr<myClass>(new myClass);
}
}
Then I have several funtions that will receive myClass by reference:
doSomething (myClass& instance)
{
instance.a = 1;
instance.b = 2;
}
And the main code, where I´m stuck:
main()
{
myFactory factory;
std::unique_ptr<myClass> instance = factory.getInstance();
doSomething(instance.get()) <--- This is not compiling
}
How do I correctly call the doSomething() function passing the instance as a reference as expected ?
Note that doSomething() will modify instance data...
operator*to access the pointee, just like your plain old raw pointer.std::make_unique(as an alternative to your factory eg.)