相关疑难解决方法(0)

什么是C++仿函数及其用途?

我一直在听C++中的仿函数.有人可以给我一个关于它们是什么的概述以及在什么情况下它们会有用吗?

c++ functor function-object function-call-operator

822
推荐指数
8
解决办法
44万
查看次数

static_cast 后面跟着两对括号是什么意思?

这句话说什么:

return static_cast<Hasher &>(*this)(key);
Run Code Online (Sandbox Code Playgroud)

我无法判断*thisor是否key被传递给static_cast. 我环顾四周,找到了这个答案,但与我所坚持的不同,第一对括号内没有任何内容。

c++ function-object

21
推荐指数
2
解决办法
2210
查看次数

为什么{}用于访问std :: hash中的operator()?

在阅读用于std :: unordered_map的std :: hash示例时,我注意到{}正在访问operator()函数.

http://en.cppreference.com/w/cpp/utility/hash

result_type operator()(argument_type const& s) const
{
    result_type const h1 ( std::hash<std::string>{}(s.first_name) );
    result_type const h2 ( std::hash<std::string>{}(s.last_name) );
    return h1 ^ (h2 << 1); // or use boost::hash_combine (see Discussion)
}
Run Code Online (Sandbox Code Playgroud)

这里使用{}代表什么?

c++ hash unordered-map c++-standard-library c++11

5
推荐指数
1
解决办法
451
查看次数