My question is this: after deleting a constructor is there any way to initialize a class? For example
class A{
    public:
        A() = delete;
        int a = 42;
        int fun(){
            a += 1; 
            return a;
        }
};
Now it should not be possible to use this class. For example you cannot:
A* instance = (A*)malloc(sizeof(A));
a->fun(); //segfault
and
A instance; //compile error undefined function
Assuming for some strange reason you actually wanted to use the class with the constructor deleted is there a way that you could do it? That is without doing something like overriding the constructor.
I know this is a strange question, but I am interested in knowing if someone has a (perhaps obscure) way of doing this. Thanks!
Aucun commentaire:
Enregistrer un commentaire