make_unique an abstract class

is it possible to make_unique an abstract class ?
i.e
1
2
//A is an abstract class
std::unique_ptr a = std::make_unique< A >( A );


note :
What I am trying to do is make a class group of SFML's drawables...this is the problem that I am facing thus far, because sf::Drawable is an abstract class...I have seen other person using reference_wrapper...but I don't want to use that technique as that makes my class share the drawable with other object, rather than owning it completely
You need to use a non-abstract class in make_unique, but the unique_ptr can be to an abstract class.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <memory>
using namespace std;

class A {
public:
    virtual void prn() = 0;
};

class B : public A {
public:
    void prn() { cout << "B\n"; }
};

class C : public A {
public:
    void prn() { cout << "C\n"; }
};

int main() {
    unique_ptr<A> a1 = make_unique<B>(B());
    unique_ptr<A> a2 = make_unique<C>(C());
    a1->prn();
    a2->prn();
}

Yeah, I get the part where unique_ptr can be used with abstract class because polymorphism...
also I decided to just use the other person's implementation which uses ref wrapper...And I succeeded with what I am trying to do...
I wonder if there is any work around though
It is not possible to create an instance of an abstract class. make_unique contains no magic that makes this possible. There's no workaround.
The reference_wrapper certainly does not create an abstract class either. It creates a [default] derived class.

The whole point of an abstract class is that it cannot be instantiated.
yeah, I know that reference_wrapper does not create, because it is just..a reference...just that
Topic archived. No new replies allowed.