Chinaunix

标题: 诡异的C++语法 [打印本页]

作者: yancncen    时间: 2007-08-01 11:40
标题: 诡异的C++语法
void test()
{
        cout << "test" << endl;
}
int main()
{
        test;//诡异的c++语法
        return 1;
}

对于test;这句,为何编译器不报错?编译器是怎么理解这一语句所表达的意思?
作者: flw    时间: 2007-08-01 11:41
指针常量,表达式语句。
作者: emacsnw    时间: 2007-08-01 11:43
函数指针吧,类似于 int *p = &some_int; p; 没啥用,但是也没错。如果开了warning的话应该有警告吧?
作者: yancncen    时间: 2007-08-01 11:49
g++的警告信息如下:
statement is a reference, not call, to function ‘test’
statement has no effect
搞明白了,谢谢!

void (*fp)() = test;
(*fp);




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2