I am using a library with a class that does not have an assignment operator implemented and the copy constructor is disabled. I can instantiate a local instance of LibraryClass
named var
like this:
LibraryClass var(data, (char *)fileName, results);
But I want to create a LibraryClass
instance variable on the class I am writing. Then I want to instantiate it in the class constructor. Something like this:
class MyClass
{
LibraryClass var;
void MyClass();
}
MyClass::MyClass()
{
var = LibraryClass(data, (char *)fileName, results);
}
In this case I end up with
error: ‘LibraryClass& LibraryClass::operator=(const LibraryClass&)’ is private
LibraryClass& operator=(const LibraryClass& rOther); // no implementation
I have tried everything I can imagine to make this work but nothing is working. Is what I am attempting to do even possible? I am out of ideas so any suggestion is much appreciated.
EDIT
I'm not actually instantiating the variable in the constructor. It's happening in a separate function. I only said constructor because I mistakenly thought it was just a simplifying assumption. I didn't realize that the initialization list would solve that problem. The main question I want to answer is the title.
How can I instantiate an instance variable of a class that doesn't have a copy constructor or assignment operator? Or is the initialization list the only way to do it?