2012-02-09 93 views
1
// t1.cpp : Defines the entry point for the console application. 
// 

#include "stdafx.h" 

struct Origin 
{ 
    Origin(int _x=0, int _y=0) : x(_x), y(_y) {} 
    int x; 
    int y; 
}; 

struct Extents 
{ 
    Extents(int _width=0, int _height=0) : width(_width), height(_height) {} 
    int width; 
    int height; 
}; 
class Rectangle 
{ 
public: 
    Rectangle(const Origin& o, const Extents& e) : m_origin(o), m_extents(e) {} 

    Origin m_origin; 
    Extents m_extents; 
}; 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
    Rectangle w(Origin(), Extents()); // declare a function 'w' 

    Origin o(1, 2); 
    Extents e(3, 4); 
    Rectangle w2(o, e);    // define a variable 'w2' 

    return 0; 
} 

問題>正如我們所看到的,w是函數的聲明。 w2是變量的定義。 從編譯器或語言的角度來看,使它們不同的關鍵區別是什麼?矩形w(Origin(),Extents())和Rectangle w2(o,e)之間的區別

+0

只需搜索「最令人頭疼的解析」。 – kennytm 2012-02-09 18:57:52

回答

1

的關鍵區別在於OriginExtends類型,而oe變量,並且不能被解釋爲類型。

相關問題