奇数__PRETTY_FUNCTION__值

时间:2013-11-27 19:33:55

标签: c++

遵循骨架代码:

struct Real
{
  virtual void method() const{}
};

typedef int (*function_t)(int);
typedef void (Real::*method_t)() const;

function_t f1()
{
  cout << __PRETTY_FUNCTION__ << endl;
  return NULL;
}

method_t f2()
{
  cout << __PRETTY_FUNCTION__ << endl;
  return NULL;
}

产生输出:

int (* f1())(int)
void (Real::* f2())()const

使用gcc 4.6.3进行编译(Ubuntu / Linaro 4.6.3-1ubuntu5)。这对我来说太不清楚了,我认为一定是:

int (*)(int) f1()
void (Real::*)()const f2()

为什么呢?也许这是一个编译器错误?

1 个答案:

答案 0 :(得分:2)

int (* f1())(int)是一个不带参数的函数,它返回一个指向函数的指针,该函数接受int类型的参数并返回int。 C声明语法有时是内部的。