Why can't I multi-declare a class

前端 未结 9 1187
我在风中等你
我在风中等你 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 first (extern) makes a reference to an existing variable. So you are just indicating the variable twice.

    The class declaration gives meaning to a type (your class: A). You are trying to give two meanings to A. This is not of any use for you, and can only confuse, so the compiler protects you from it.

    Btw, if you put both classes in difference namespaces you can give them the same name.

提交回复
热议问题