dimanche 5 mai 2019

Declare member variables that do not have a default constructor nor a copy constructor

Assume I have class Member that does not have neither a default constructor nor a copy constructor, and it gets created by a third party API as with a function.

I have the declaration

class MyClass {
    Member my_member;
public:
    MyClass(){
       my_member = CreateMember("I am a parameter");
    }
}

Since the class Member has no default constructor, the above declaration doesn't work, as there is no way to initialize the member.

I also cannot declare it as a pointer, since the lack of copy constructor means I can't call new Member(my_member).

I am at a loss here, any suggestions?

Aucun commentaire:

Enregistrer un commentaire