Why can't I multi-declare a class

前端 未结 9 1281
我在风中等你
我在风中等你 2021-01-12 04:03

I can do this

extern int i;
extern int i;

But I can\'t do the same with a class

class A {
..
}
class A {
..
}
9条回答
  •  甜味超标
    2021-01-12 04:27

    The following are declarations:

    extern int i;
    class A;
    

    And the next two are definitions:

    int i;
    class A { ... };
    

    The rules are:

    • a definition is also a declaration.
    • you have to have 'seen' a declaration of an item before you can use it.
    • re-declaration is OK (must be identical).
    • re-definition is an error (the One Definition Rule).

提交回复
热议问题