2011-12-01 155 views
0
#include <iostream> 

std::string getMyName(void) 
{ 
    std:: cout << "This is function getMyName" << std::endl; 
    return std::string("hello world"); 
} 

std::string getMyName2(void) 
{ 
    std:: cout << "This is function getMyName2" << std::endl; 
    return std::string("hello world2"); 
} 

int main(void) 
{ 
    // what is the official name for the following syntax? 
    bool isDone = (getMyName(), getMyName2(), false); 

    std:: cout << "isDone " << isDone << std::endl; 
    return 0; 
} 

[email protected]:~/Documents/C++$ ./period 
This is function getMyName 
This is function getMyName2 
isDone 0 

正如你可以看到下面的语句进行评估。C++的这种语法名(exprA,exprB,exprC)

bool isDone = (getMyName(), getMyName2(), false); 

我想知道这个声明的官方语法名称。我已经通过G搜索了“期限声明”,没有有意义的点击。

谢谢

+0

作为一个说明,我不会使用这样的代码。作为一个经验法则,你通常不想做一个有副作用的赋值操作符。你可能知道'getMyName()'有副作用,但其他人可能不会。最好是做一些像@ JaredPar建议的事情。 –

回答