我在临时对象上调用操作符时遇到了一些问题。我已经将代码剥离了基本问题:
template<typename T, typename OP>
struct X
{
X( const OP &op ) : m_op( op ) { }
X &operator ()( T *pa, size_t n ) { /* ... */ return *this; }
OP m_op;
};
int main()
{
// Why does this work ...
((X<int, less<int>>)( less<int>() ))( nullptr, 123 );
// ... this doesn't work ...
// (X<int, less<int>>)( less<int>() )( nullptr, 123 );
// ... and this also doesn't work ...
// X<int, less<int>>( less<int>() )( nullptr, 123 );
}
这可能对我的编译器来说很特殊(VC ++ 2015)。