尝试在 std::map 中插入抽象类时没有用于调用的匹配函数
no matching function for call to when try to insert an abstract class inside the std::map
我正在尝试使用此代码添加创建带有字符串键和抽象类值的映射
using Commands = = std::map<std::string, std::shared_ptr<spyCBlockRPC::IRPCCommand>>;
RPCCommandMediator {
public:
Commands commands = {
{"DECODE_SCRIPT_COMMAND", std::shared_ptr<IRPCCommand *>(new DecodeScriptCommand())},
};
}
此代码如何编写抽象类
class IRPCCommand
{
public:
virtual void doCommand(WrapperInformations &wrapper, BitcoinAPI &bitcoinApi) = 0;
};
具体类由此代码编写
class DecodeScriptCommand : public IRPCCommand
{
public:
DecodeScriptCommand();
void doCommand(WrapperInformations &wrapper, BitcoinAPI &bitcoinApi) override;
};
文件CPP是
DecodeScriptCommand::DecodeScriptCommand() : IRPCCommand(){}
void DecodeScriptCommand::doCommand(WrapperInformations &wrapper, BitcoinAPI &bitcoinApi)
{
//Operations
}
编译时,我有这个错误
In file included from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:0:
/home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:80:93: error: no matching function for call to ‘std::shared_ptr<spyCBlockRPC::IRPCCommand*>::shared_ptr(spyCBlockRPC::DecodeScriptCommand*)’
{DECODE_SCRIPT_COMMAND, std::shared_ptr<IRPCCommand *>(new DecodeScriptCommand())},
^
In file included from /usr/include/c++/7/memory:81:0,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:6,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:
/usr/include/c++/7/bits/shared_ptr.h:352:7: note: candidate: std::shared_ptr<_Tp>::shared_ptr(const std::weak_ptr<_Tp>&, std::nothrow_t) [with _Tp = spyCBlockRPC::IRPCCommand*]
shared_ptr(const weak_ptr<_Tp>& __r, std::nothrow_t)
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:352:7: note: candidate expects 2 arguments, 1 provided
/usr/include/c++/7/bits/shared_ptr.h:342:2: note: candidate: template<class _Alloc, class ... _Args> std::shared_ptr<_Tp>::shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...)
shared_ptr(_Sp_make_shared_tag __tag, const _Alloc& __a,
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:342:2: note: template argument deduction/substitution failed:
In file included from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:0:
/home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:80:93: note: candidate expects at least 2 arguments, 1 provided
{DECODE_SCRIPT_COMMAND, std::shared_ptr<IRPCCommand *>(new DecodeScriptCommand())},
^
In file included from /usr/include/c++/7/memory:81:0,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:6,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:
/usr/include/c++/7/bits/shared_ptr.h:294:17: note: candidate: constexpr std::shared_ptr<_Tp>::shared_ptr(std::nullptr_t) [with _Tp = spyCBlockRPC::IRPCCommand*; std::nullptr_t = std::nullptr_t]
constexpr shared_ptr(nullptr_t) noexcept : shared_ptr() { }
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:294:17: note: no known conversion for argument 1 from ‘spyCBlockRPC::DecodeScriptCommand*’ to ‘std::nullptr_t’
/usr/include/c++/7/bits/shared_ptr.h:286:2: note: candidate: template<class _Yp, class _Del, std::shared_ptr<spyCBlockRPC::IRPCCommand*>::_Constructible<std::unique_ptr<_Tp, _Dp>, std::__sp_array_delete>* <anonymous> > std::shared_ptr<_Tp>::shared_ptr(std::unique_ptr<_Up, _Ep>&&)
shared_ptr(unique_ptr<_Yp, _Del>&& __r)
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:286:2: note: template argument deduction/substitution failed:
In file included from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:0:
/home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:80:93: note: mismatched types ‘std::unique_ptr<_Tp, _Dp>’ and ‘spyCBlockRPC::DecodeScriptCommand*’
{DECODE_SCRIPT_COMMAND, std::shared_ptr<IRPCCommand *>(new DecodeScriptCommand())},
^
In file included from /usr/include/c++/7/memory:81:0,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:6,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:
/usr/include/c++/7/bits/shared_ptr.h:277:2: note: candidate: template<class _Yp, class _Del, class> std::shared_ptr<_Tp>::shared_ptr(std::unique_ptr<_Up, _Ep>&&)
shared_ptr(unique_ptr<_Yp, _Del>&& __r)
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:277:2: note: template argument deduction/substitution failed:
In file included from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:0:
/home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:80:93: note: mismatched types ‘std::unique_ptr<_Tp, _Dp>’ and ‘spyCBlockRPC::DecodeScriptCommand*’
{DECODE_SCRIPT_COMMAND, std::shared_ptr<IRPCCommand *>(new DecodeScriptCommand())},
^
In file included from /usr/include/c++/7/memory:81:0,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:6,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:
/usr/include/c++/7/bits/shared_ptr.h:270:2: note: candidate: template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(std::auto_ptr<_Up>&&)
shared_ptr(auto_ptr<_Yp>&& __r);
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:270:2: note: template argument deduction/substitution failed:
In file included from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:0:
/home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:80:93: note: mismatched types ‘std::auto_ptr<_Up>’ and ‘spyCBlockRPC::DecodeScriptCommand*’
{DECODE_SCRIPT_COMMAND, std::shared_ptr<IRPCCommand *>(new DecodeScriptCommand())},
^
In file included from /usr/include/c++/7/memory:81:0,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:6,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:
/usr/include/c++/7/bits/shared_ptr.h:265:11: note: candidate: template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(const std::weak_ptr<_Yp>&)
explicit shared_ptr(const weak_ptr<_Yp>& __r)
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:265:11: note: template argument deduction/substitution failed:
In file included from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:0:
/home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:80:93: note: mismatched types ‘const std::weak_ptr<_Tp>’ and ‘spyCBlockRPC::DecodeScriptCommand*’
{DECODE_SCRIPT_COMMAND, std::shared_ptr<IRPCCommand *>(new DecodeScriptCommand())},
^
In file included from /usr/include/c++/7/memory:81:0,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:6,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:
/usr/include/c++/7/bits/shared_ptr.h:253:2: note: candidate: template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(std::shared_ptr<_Yp>&&)
shared_ptr(shared_ptr<_Yp>&& __r) noexcept
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:253:2: note: template argument deduction/substitution failed:
In file included from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:0:
/home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:80:93: note: mismatched types ‘std::shared_ptr<_Tp>’ and ‘spyCBlockRPC::DecodeScriptCommand*’
{DECODE_SCRIPT_COMMAND, std::shared_ptr<IRPCCommand *>(new DecodeScriptCommand())},
^
In file included from /usr/include/c++/7/memory:81:0,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:6,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:
/usr/include/c++/7/bits/shared_ptr.h:244:7: note: candidate: std::shared_ptr<_Tp>::shared_ptr(std::shared_ptr<_Tp>&&) [with _Tp = spyCBlockRPC::IRPCCommand*]
shared_ptr(shared_ptr&& __r) noexcept
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:244:7: note: no known conversion for argument 1 from ‘spyCBlockRPC::DecodeScriptCommand*’ to ‘std::shared_ptr<spyCBlockRPC::IRPCCommand*>&&’
/usr/include/c++/7/bits/shared_ptr.h:236:2: note: candidate: template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(const std::shared_ptr<_Yp>&)
shared_ptr(const shared_ptr<_Yp>& __r) noexcept
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:236:2: note: template argument deduction/substitution failed:
In file included from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:0:
/home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:80:93: note: mismatched types ‘const std::shared_ptr<_Tp>’ and ‘spyCBlockRPC::DecodeScriptCommand*’
{DECODE_SCRIPT_COMMAND, std::shared_ptr<IRPCCommand *>(new DecodeScriptCommand())},
^
In file included from /usr/include/c++/7/memory:81:0,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:6,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:
/usr/include/c++/7/bits/shared_ptr.h:224:2: note: candidate: template<class _Yp> std::shared_ptr<_Tp>::shared_ptr(const std::shared_ptr<_Yp>&, std::shared_ptr<_Tp>::element_type*)
shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) noexcept
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:224:2: note: template argument deduction/substitution failed:
In file included from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:0:
/home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:80:93: note: mismatched types ‘const std::shared_ptr<_Tp>’ and ‘spyCBlockRPC::DecodeScriptCommand*’
{DECODE_SCRIPT_COMMAND, std::shared_ptr<IRPCCommand *>(new DecodeScriptCommand())},
^
In file included from /usr/include/c++/7/memory:81:0,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:6,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:
/usr/include/c++/7/bits/shared_ptr.h:202:2: note: candidate: template<class _Deleter, class _Alloc> std::shared_ptr<_Tp>::shared_ptr(std::nullptr_t, _Deleter, _Alloc)
shared_ptr(nullptr_t __p, _Deleter __d, _Alloc __a)
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:202:2: note: template argument deduction/substitution failed:
In file included from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:0:
/home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:80:93: note: candidate expects 3 arguments, 1 provided
{DECODE_SCRIPT_COMMAND, std::shared_ptr<IRPCCommand *>(new DecodeScriptCommand())},
^
In file included from /usr/include/c++/7/memory:81:0,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:6,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:
/usr/include/c++/7/bits/shared_ptr.h:183:2: note: candidate: template<class _Yp, class _Deleter, class _Alloc, class> std::shared_ptr<_Tp>::shared_ptr(_Yp*, _Deleter, _Alloc)
shared_ptr(_Yp* __p, _Deleter __d, _Alloc __a)
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:183:2: note: template argument deduction/substitution failed:
In file included from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:0:
/home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:80:93: note: candidate expects 3 arguments, 1 provided
{DECODE_SCRIPT_COMMAND, std::shared_ptr<IRPCCommand *>(new DecodeScriptCommand())},
^
In file included from /usr/include/c++/7/memory:81:0,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:6,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:
/usr/include/c++/7/bits/shared_ptr.h:163:2: note: candidate: template<class _Deleter> std::shared_ptr<_Tp>::shared_ptr(std::nullptr_t, _Deleter)
shared_ptr(nullptr_t __p, _Deleter __d)
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:163:2: note: template argument deduction/substitution failed:
In file included from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:0:
/home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:80:93: note: candidate expects 2 arguments, 1 provided
{DECODE_SCRIPT_COMMAND, std::shared_ptr<IRPCCommand *>(new DecodeScriptCommand())},
^
In file included from /usr/include/c++/7/memory:81:0,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:6,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:
/usr/include/c++/7/bits/shared_ptr.h:146:2: note: candidate: template<class _Yp, class _Deleter, class> std::shared_ptr<_Tp>::shared_ptr(_Yp*, _Deleter)
shared_ptr(_Yp* __p, _Deleter __d)
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:146:2: note: template argument deduction/substitution failed:
In file included from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:0:
/home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:80:93: note: candidate expects 2 arguments, 1 provided
{DECODE_SCRIPT_COMMAND, std::shared_ptr<IRPCCommand *>(new DecodeScriptCommand())},
^
In file included from /usr/include/c++/7/memory:81:0,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:6,
from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:
/usr/include/c++/7/bits/shared_ptr.h:129:2: note: candidate: template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(_Yp*)
shared_ptr(_Yp* __p) : __shared_ptr<_Tp>(__p) { }
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:129:2: note: template argument deduction/substitution failed:
/usr/include/c++/7/bits/shared_ptr.h:119:7: note: candidate: std::shared_ptr<_Tp>::shared_ptr(const std::shared_ptr<_Tp>&) [with _Tp = spyCBlockRPC::IRPCCommand*]
shared_ptr(const shared_ptr&) noexcept = default;
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:119:7: note: no known conversion for argument 1 from ‘spyCBlockRPC::DecodeScriptCommand*’ to ‘const std::shared_ptr<spyCBlockRPC::IRPCCommand*>&’
/usr/include/c++/7/bits/shared_ptr.h:117:17: note: candidate: constexpr std::shared_ptr<_Tp>::shared_ptr() [with _Tp = spyCBlockRPC::IRPCCommand*]
constexpr shared_ptr() noexcept : __shared_ptr<_Tp>() { }
^~~~~~~~~~
/usr/include/c++/7/bits/shared_ptr.h:117:17: note: candidate expects 0 arguments, 1 provided
In file included from /home/vincenzo/Github/SpyCBlockRPC/src/core/graph/TransactionGraph.cpp:4:0:
/home/vincenzo/Github/SpyCBlockRPC/src/core/graph/../../commands/RPCCommandMediator.h:81:7: error: could not convert ‘{{((spyCBlockRPC::RPCCommandMediator*)this)->spyCBlockRPC::RPCCommandMediator::DECODE_SCRIPT_COMMAND, <expression error>}}’ from ‘<brace-enclosed initializer list>’ to ‘Commands {aka std::map<std::__cxx11::basic_string<char>, std::shared_ptr<spyCBlockRPC::IRPCCommand> >}’
};
一些信息
我已经阅读了这个和这个,但我没有修复我的错误(也许我没有取消它(
看起来您不应该将IRPCCommand *
放在shared_ptr模板参数中,您只想将IRPCCommand
对象存储在shared_ptr中。
喜欢这个:
{"DECODE_SCRIPT_COMMAND", std::shared_ptr<IRPCCommand>(new DecodeScriptCommand())},
或者,您可以使用make_shared
:
{"DECODE_SCRIPT_COMMAND", std::make_shared<IRPCCommand>(new DecodeScriptCommand())},
相关文章:
- 用于在回调中调用解析器的设计模式
- Arduino SocketIoClient - 没有用于调用的匹配函数
- 如何调用用于重载运算符"<<"的 friend 函数?
- boost::bind()类似的东西,但用于函数调用
- Rcpp并行无匹配函数,用于调用"转换"
- 没有用于调用默认构造函数的匹配函数
- OpenMP 内部的函数调用用于循环
- 我正在尝试学习如何在 c++ 中传递指针,但出现错误:没有用于调用"test"的匹配函数。我做错了什么?
- c++ 中的自定义分配器,用于不调用secure_string实现
- 将内联程序集尾调用函数尾声替换为用于x86/x64 msvc的Intrinsics
- 调用函数一次用于动态链接库,一次从可执行文件调用函数
- 是否可以在运行时调用用于选择要调用的用户定义文本的逻辑?
- c++\CLI dll包装器,用于调用c++类中的虚拟成员
- 尝试在 std::map 中插入抽象类时没有用于调用的匹配函数
- C++实用程序,用于将长开关语句转换为封装开关案例阶梯的简洁函数调用
- 没有用于调用 foo 的匹配函数
- 用户指定的参数,用于确定在大循环中调用哪个函数
- 多个调用异步,用于C++中的更新向量或列表
- qt并发没有用于调用"运行"的匹配函数
- P/调用C++用于填充托管缓冲区的 DLL