Why can't I multi-declare a class

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

    The closest equivalent to extern int i with a class is a forward declaration, which you can do as many times as you like:

    class A;
    
    class A;
    
    class A;
    
    class A{};
    

    When you define the actual class you are saying how much memory is required to construct an instance of it, as well as how that memory is laid out. That's not really the issue here, though.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题