我最近在学C++的stl,MSDN里有这样一段代码:
template <class Type>
class MultValue
{
private:
Type Factor; // The value to multiply by
public:
// Constructor initializes the value to multiply by
MultValue ( const Type& value ) : Factor ( value ) { }
// The function call for the element to be multiplied
Type operator( ) ( Type& elem ) const
{
return elem * Factor;
}
};
transform (v1.begin( ), v1.end( ), v1.begin( ), MultValue<int> ( 2 ) );
我想问下transform中最后一个参数是函数指针,他这样写的原理是什么,是不是里面重载了()就可以这样写,还有对于模板类,MultValue,这样的初始化MultValue<int>() 不用写对象名就可以调用构造函数,这个特性是怎样的。