对于增压信号,尖括号内的括号是什么意思? 在我的C++基础上,没有下述类声明。 对我来说奇怪的代码是 boost::signals2::signal<bool (const std::string& message, const std::string& caption, unsigned int style), boost::signals2::last_value<bool> > ThreadSafeMessageBox;
预期作为模板参数对于增压信号,尖括号内的括号是什么意思? 在我的C++基础上,没有下述类声明。 对我来说奇怪的代码是 boost::signals2::signal<bool (const std::string& message, const std::string& caption, unsigned int style), boost::signals2::last_value<bool> > ThreadSafeMessageBox;,c++,templates,parentheses,boost-signals2,C++,Templates,Parentheses,Boost Signals2,预期作为模板参数签名的类型是函数签名,即预期函数参数编号、类型和返回类型的规范 就你而言 boost::signals2::signal<bool (const std::string& message, const std::string& caption, unsigned int style), boost::signals2::last_value<bool> > ThreadSafeMessageBox; 这是一个具有3个参数(类型为strin
签名的类型是函数签名,即预期函数参数编号、类型和返回类型的规范
就你而言
boost::signals2::signal<bool (const std::string& message, const std::string& caption, unsigned int style), boost::signals2::last_value<bool> > ThreadSafeMessageBox;
这是一个具有3个参数(类型为string
、string
和unsigned int
)并返回bool的函数。请查阅以下文档:
Boost.Signals2库是托管信号和插槽系统的实现信号表示具有多个目标的回调
所以我们知道“信号”与“回调”有关。是一个以后调用的函数
那么,请查看文档中的示例:
struct HelloWorld
{
void operator()() const
{
std::cout << "Hello, World!" << std::endl;
}
};
// ...
// Signal with no arguments and a void return value
boost::signals2::signal<void ()> sig;
// Connect a HelloWorld slot
HelloWorld hello;
sig.connect(hello);
// Call all of the slots
sig();
ThreadSafeMessageBox
是一种可以连接到以下功能的信号:
- 返回
bool
- 获取第一个参数
const std::string&
- 获取第二个参数
const std::string&
- 接受第三个参数
unsigned int
< P>(第二个模板参数,我们可以忽略这个问题,它不是一个必需的模板参数,也不是回调函数签名的一部分,而是所谓的)< /P>不是一个好主意,用C++代码****/CODE来强调C++代码的一部分。它是一个函数类型。
bool (const std::string& message, const std::string& caption, unsigned int style)
struct HelloWorld
{
void operator()() const
{
std::cout << "Hello, World!" << std::endl;
}
};
// ...
// Signal with no arguments and a void return value
boost::signals2::signal<void ()> sig;
// Connect a HelloWorld slot
HelloWorld hello;
sig.connect(hello);
// Call all of the slots
sig();
boost::signals2::signal<bool (const std::string& message,
const std::string& caption,
unsigned int style),
boost::signals2::last_value<bool>
> ThreadSafeMessageBox;