开发者

Importing a class imports the classes it has imported automatically

If I have three classes:

ClassA ClassB ClassC

They all have import statements to import ea开发者_C百科ch other i.e. ClassC imports ClassB and ClassB imports ClassA only.

Given this design, does ClassC have access to ClassA automatically?


First: in any case import/include doesn't make one class to have access to another class, it just makes class A to know about class B.

Second: visibility is determined by where you imported headers. If you did import ClassA header in the ClassB header and then imported ClassB header in ClassC header than yes, ClassC knows about ClassA. But if imported it in an implementation file then the answer is no.

Edit: should notice that it's better to make class forward declarations in header and then include appropriate one in an implementation file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜