c++ - 调用运算符和默认构造函数
阿神
阿神 2017-04-17 14:58:39
0
2
633

关于符号(),它不是用在类名后面作用是调用默认构造函数,用在类的对象后边作用是函数调用运算符嘛。
但是在书里边有这样一行代码sort(svec.begin(),svec.end(),greater<string>());为嘛说它是调用给定的greater函数对象呢?

阿神
阿神

闭关修行中......

reply all(2)
迷茫

means that greater<string>() returns a function object constructed by calling the default constructor

Peter_Zhu

greater is a class template, which overloads the operator() internally. In addition, function objects are defined as follows function objects are instances of a class with member operator() defined. this member function allows the object to be used with the same syntax as a function call. Therefore, the object of greater is a function object. greater<string>(), calls the default constructor to generate a temporary object.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!