我懷疑下面的函數鏈會根據C++標準(假設C++ 0x)導致未指定的序列。只需要確認,如果有人可以提供解釋,我會很感激。這段代碼是否定義良好?
#include <iostream>
struct TFoo
{
TFoo(int)
{
std::cout<<"TFoo"<<std::endl;
};
TFoo foobar1(int)
{
std::cout<<"foobar1"<<std::endl;
return *this;
};
TFoo foobar2(int)
{
std::cout<<"foobar2"<<std::endl;
return *this;
};
static int bar1()
{
std::cout<<"bar1"<<std::endl;
return 0;
};
static int bar2()
{
std::cout<<"bar2"<<std::endl;
return 0;
};
static int bar3()
{
std::cout<<"bar3"<<std::endl;
return 0;
}
};
int main(int argc, char *argv[])
{
// is the sequence well defined for bar1, bar2 and bar3?
TFoo(TFoo::bar1()).foobar1(TFoo::bar2()).foobar2(TFoo::bar3());
}
*編輯:刪除__fastcall符的功能(不要求/有關的問題)。
我不是故意要碰到nitpicky,但從技術上講,'__fastcall'不是C++規範的一部分,所以我不認爲規範有什麼可說的。你有什麼理由將它包含在這裏嗎?或者是關於'__fastcall'與序列點的交互的具體問題? – templatetypedef