I'm designing a class that has to get ownership of a unique_ptr and do sth with it. Here is a minimized version of the code:
Chunk.h:
class Chunk {
public:
Chunk(std::unique_ptr<unsigned char[]> contents);
std::unique_ptr<char[]> contents;
};
Chunk.cpp:
Chunk::Chunk(std::unique_ptr<unsigned char[]> content):
contents(std::move(content)){ }
but it couldn't compiled though to this error:
no matching function for call to ‘std::unique_ptr<char []>::unique_ptr(std::remove_reference<std::unique_ptr<unsigned char []>&>::type)’
You are using a <unsigned char[]> template as argument and <char[]> template as member.
They are not even considered as the same class at all by the compiler. Use exactly the same type if you plan to use template functions like std::move with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With