boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 请教一个C++ typedef的问题
相关主题
用STL map的时候怎么自己定义大小比较的关系
请教一个boost::bind的问题
问两个C++语法问题
请教C++ call-by-ref & call-by-val的问题
请教一个c++ 里functor的问题
把一个function pointer作为参数传入一个function的语法是什么?
template 疑问
function pointer 和 call-back function 有什么区别?
[合集] 大家看看我这个C++ STL Functor那里写错了
呼唤大侠们,我实在不能实现C++泛型的精神。
相关话题的讨论汇总
话题: mypq话题: typedef话题: type话题: int
进入Programming版参与讨论
1 (共1页)
d**********u
发帖数: 3371
1
这里面 在typedef定义了priority_queue的新类型之后 可以用
mypq_type fifth(mycomparison(true)); // greater-than comparison
来取代指点定义中的最后一个template 参数
但是假如要取代其中一个或者两个参数呢
试验了一下并不成功 比如
mypq_type six(deque, mycomparision(true));
谢谢
class mycomparison
{
bool reverse;
public:
mycomparison(const bool& revparam = false)
{
reverse = revparam;
}
bool operator() (const int& lhs, const int&rhs) const
{
if (reverse) return (lhs>rhs);
else return (lhs }
};
int main()
{
// using mycomparison:
typedef std::priority_queue, mycomparison>
mypq_type;
mypq_type fourth; // less-than comparison
mypq_type fifth(mycomparison(true)); // greater-than comparison
mypq_type six(mycomparison(true)); // greater-than comparison
while (1);
return 0;
}
t****t
发帖数: 6806
2
container type, as well as comparison functor, are types. you need to define
it in the typedef, e.g.
typedef priority_queue, mycomparison> mypq_type1;

【在 d**********u 的大作中提到】
: 这里面 在typedef定义了priority_queue的新类型之后 可以用
: mypq_type fifth(mycomparison(true)); // greater-than comparison
: 来取代指点定义中的最后一个template 参数
: 但是假如要取代其中一个或者两个参数呢
: 试验了一下并不成功 比如
: mypq_type six(deque, mycomparision(true));
: 谢谢
: class mycomparison
: {
: bool reverse;

d**********u
发帖数: 3371
3
谢谢
那么关于这一行的用法
mypq_type fifth(mycomparison(true));
其作用只是给之前typedef中的mycomparision传递一个参数么?

define

【在 t****t 的大作中提到】
: container type, as well as comparison functor, are types. you need to define
: it in the typedef, e.g.
: typedef priority_queue, mycomparison> mypq_type1;

t****t
发帖数: 6806
4
是的.

【在 d**********u 的大作中提到】
: 谢谢
: 那么关于这一行的用法
: mypq_type fifth(mycomparison(true));
: 其作用只是给之前typedef中的mycomparision传递一个参数么?
:
: define

d**********u
发帖数: 3371
5
明白了 谢谢!

【在 t****t 的大作中提到】
: 是的.
1 (共1页)
进入Programming版参与讨论
相关主题
呼唤大侠们,我实在不能实现C++泛型的精神。
C++ 程序求助
what is the difference?
C++ Q02:
stl Compare为何需要重载()?
C++ template Questions (转载)
access function static variable
C++ STL 的问题
lambda的一个疑问
请教C++中的unordered_set
相关话题的讨论汇总
话题: mypq话题: typedef话题: type话题: int