【发布时间】:2021-07-07 07:50:50
【问题描述】:
#include <iostream>
struct S
{
void operator()(char c){ std::cout << c << std::endl; };
void operator()(const char * p)
{
while( *p != '\0' )
{
this( *p++ ); # error: expression cannot be used as a function
}
}
} s ;
int main()
{
s( "blqhblqh" );
}
如何调用重载版本?
【问题讨论】:
-
(*this)(*p++)或this->operator()(*p++)或operator()(*p++)。decltype(this)是struct S*不是struct S。