2011-03-23 84 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