Why can't I multi-declare a class

前端 未结 9 1293
我在风中等你
我在风中等你 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:23

    You can declare a class and an object multiple times, what you can't do is define it more than once.

    extern makes this a declaration and not a definition (because there is no initializer):

    extern int a;
    

    The body makes your class a definition and not just a declaration. You can define a class once.

提交回复
热议问题