2008年7月23日 星期三

Self initialization

int i = i;
這樣做gcc竟然沒問題....
再來看看C++的例子:
struct Test {
    Test() : i_( 0 ) {
        std::cout << "Default constructor" << std::endl;
    }
    Test( const Test & rhs ) : i_( rhs.i_ ) {
        std::cout << "Copy constructor" << std::endl;
    }
private:
    int i_;
};
int main() {
    Test a( a );
    return 0;
}
可以看到只印出一個Copy contructor出來....而內部的變數是未定義的。

沒有留言:

張貼留言