【发布时间】:2014-08-17 15:07:04
【问题描述】:
我正在学习 C++,对使用 Trust Library 的 C++ 代码有点困惑。以下是我的问题:
- 为什么要使用关键字
struct? -
为什么函数
is_word_start有冒号部分::public push::binary_function"// determines whether the right character begins a new word struct is_word_start : public thrust::binary_function<const char&, const char&, bool> { __host__ __device__ bool operator()(const char& left, const char& right) const { return is_alpha(right) && !is_alpha(left); } };
https://github.com/thrust/thrust/blob/master/examples/word_count.cu
【问题讨论】:
-
函数执行
operator()可以在这个类的实例上调用,因此可以作为简单函数调用的替代调用。 -
请继续学习C++。此时您可能还没有为 Stack Overflow 做好准备。
-
is_word_start是 class,而不是函数。 -
冒号部分表示继承。此外 is_word_start 不是一个函数,而是一个function object 类。
标签: c++