Reputation: 302
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)’
Upvotes: 3
Views: 1369
Reputation: 5907
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.
Upvotes: 7