2011-03-23 71 views
0

形式ISO標準草案檢查這是正確的還是不

n3234說:

Two names are the same if 
— they are identifier s composed of the same character sequence, or 

根據這一meaning..Check是否正確與否

class ABC{}; 
class abc{}; 
int ABC(){} 
int abc(){} 
int main(){ 
      int abc; 
      char ABC; 
     } 

是這個節目根據上述說法是否正確?

是這個計劃是APT這一說法?(這是什麼意思發言代表)

最後..explain任何其他東西..是我離開?

回答

3

從ISO/IEC 14882:2003(E)9.1.2 -

一個類的定義介紹了類名字進入其中它被定義並隱藏任何類,對象,功能,或其他聲明的範圍這個名字在封閉的範圍內(3.3)。如果在聲明同名對象,函數或枚舉器的作用域中聲明瞭類名,那麼當兩個聲明都在作用域中時,該類只能使用詳細類型說明符來引用( 3.4.4)。

[實施例:

struct stat { 
    // ... 
}; 

stat gstat; // use plain stat to 
       // define variable 

int stat(struct stat*); // redeclare stat as function 

void f() { 
    struct stat* ps; stat(ps); // struct prefix needed 
           // to name struct stat 
           // ... 
} 

末端示例]

3.3.7名稱隱藏

2所述的類名(9.1)或枚舉名稱(7.2)可以通過在同一範圍內聲明的對象,函數或枚舉的名稱來隱藏。如果類或枚舉名稱和對象,函數或枚舉器在相同的作用域(以任何順序)中聲明具有相同的名稱,則無論對象,函數或枚舉器名稱是否可見,都將隱藏類或枚舉名稱。


與標準的報價,所有這些說法都是正確的。

class ABC{}; 
class abc{}; // abc and ABC are two different character sequences for the 
       // class entity. And similar is the case for next two function 
       // entities. 

int ABC(){} 
int abc(){} 

int main(){  
    int abc; // abc and ABC are two different character sequences. 
    char ABC; 
} 

最後..explain任何其他東西..是我離開?

兩者的功能ABC(), abc()應該返回int,它們不這樣做雖然:)

2

C++承認大小寫,所以是上面確實符合。

ABC和abc是有區別的 - 它們是完全不同的標識符。 但是,使用這種區別在現實世界中製作唯一標識符是不鼓勵的,因爲它實際上可以確保您在某個時刻將它們混合在一起。

需要注意的是,

int abc(); 
int abc(); 

是非法的,但

int abc(); 
int ABC(); 

不是。

+0

'INT ABC(); int abc();'實際上不是非法的。它只是重新宣佈相同的功能。 (這種重新聲明很容易發生在前向聲明中。) – UncleBens 2011-03-23 22:15:52

相關問題