3

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)’ 
4
  • 8
    Why are you using a <unsigned char[]> template as argument and <char[]> template as member? Commented Jan 13, 2016 at 11:56
  • Surely the argument should be a non-const reference to a unique_ptr, or an rvalue reference(&&)? Commented Jan 13, 2016 at 12:01
  • 2
    @Aracthor oh no! It's about 3 hours that Im checking it and i don't notice this silly mistake! Commented Jan 13, 2016 at 12:02
  • @MartinBonner It works without reference as well Commented Jan 13, 2016 at 12:03

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.