avatar
Question about friend in C++# Programming - 葵花宝典
l*e
1
to define A:Func1 as a friend function of class B, can we seperate the
declaration of A and B in different files?
I know the following codes work, but it uses forward declaration and
mandates the declaration of A and B exist in the same source file. Is there
any way to seperate the declaration of A and B into two header files?
avatar
l*e
2
ding yi xia , you ren zhidao da an me?

there

【在 l******e 的大作中提到】
: to define A:Func1 as a friend function of class B, can we seperate the
: declaration of A and B in different files?
: I know the following codes work, but it uses forward declaration and
: mandates the declaration of A and B exist in the same source file. Is there
: any way to seperate the declaration of A and B into two header files?

avatar
p*o
3
of course, but you still need to include the header of B in the header of A.
does it buy you anything?

there

【在 l******e 的大作中提到】
: to define A:Func1 as a friend function of class B, can we seperate the
: declaration of A and B in different files?
: I know the following codes work, but it uses forward declaration and
: mandates the declaration of A and B exist in the same source file. Is there
: any way to seperate the declaration of A and B into two header files?

avatar
l*e
4
header of B has A::Func1( ..) as the friend function, so when B is compiled,
the compiler cannot recognized A if they're in two files, I got compiler
error.

A.

【在 p****o 的大作中提到】
: of course, but you still need to include the header of B in the header of A.
: does it buy you anything?
:
: there

avatar
d*e
5
try adding keyword 'class' before A. as such:
friend int class A::Func1(..)

compiled,

【在 l******e 的大作中提到】
: header of B has A::Func1( ..) as the friend function, so when B is compiled,
: the compiler cannot recognized A if they're in two files, I got compiler
: error.
:
: A.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。