0

I have such a code: Link to Wandbox

When I try to compile it I'm getting this:

./type_holder.h:45:14: error: no matching constructor for initialization of 'test_class'
                return new T(args...);
                           ^ ~~~~
./type_holder.h:54:35: note: in instantiation of member function 'di::DiConstructor<true, test_class, di::DiMark &&, di::AnyResolver>::construct' requested
      here
                                                         decltype(AnyResolver())>::construct(std::move(DiMark{}), AnyResolver{});
                                                                                   ^
test.cc:26:19: note: in instantiation of function template specialization 'di::ConstructIfPossible<test_class>' requested here
        std::cout << di::ConstructIfPossible<test_class>() << std::endl;
                         ^
test.cc:14:9: note: candidate constructor not viable: no known conversion from 'di::DiMark' to 'di::DiMark &&' for 1st argument
        INJECT(test_class, int* a) {}
               ^
./inject_markers.h:6:36: note: expanded from macro 'INJECT'
#define INJECT(name, ...) explicit name(di::DiMark&& m, __VA_ARGS__)
                                   ^
test.cc:12:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
class test_class {
      ^
test.cc:12:7: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided
1 error generated.

The question is what am I doing wrong? Why does compiler tells me that I'm trying to convert DiMark to DiMark&&? Should it not be DiMark&& already since I did std::move(DiMark) {} explicitly converting lvalue to rvalue?

s0nicYouth
  • 470
  • 3
  • 15

1 Answers1

1

What the errors are telling you is that you're trying to construct a test_class object using a two parameter constructor, but you haven't defined any.

There are two constructors, both implicitly defined, that take one parameter (the copy constructor, and the move constructor). However, since you're trying to construct a test_class object with both a DiMark and AnyResolver arguments, and this constructor does not exist, you get the error.

To resolve this you need to create a two parameter constructor. (And you then may need to define the copy and move constructors, since the implicit constructors will not be defined if you define any other constructors.)

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56