【发布时间】:2017-09-22 15:33:18
【问题描述】:
我有这样的代码: Link to Wandbox
当我尝试编译它时,我得到了这个:
./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.
问题是我做错了什么?为什么编译器告诉我我正在尝试将DiMark 转换为DiMark&&?既然我做了std::move(DiMark) {} 明确地将左值转换为右值,它不应该是DiMark&& 吗?
【问题讨论】:
-
如果你能发一个minimal reproducible example会很有帮助。
-
显示的代码不符合minimal reproducible example的要求,否则无法完全分析。
-
test_class是什么? -
更新了评论并添加了指向 Wandbox 的链接
-
请在问题中发布问题代码,而不是在场外链接上,这样当您的场外链接中断时,问题仍然具有一些可能的价值。
标签: c++ c++11 metaprogramming std stdmove