由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Question about friend in C++
相关主题
一道面试怪题C++. (转载)基础问题:在header里面define function
关于C++ STL编译的疑问Qt Creator
请教有关header file的几个问题Question about
ask a question about compile shared library using libtoolHow to see the content of a library file
forward declarationwhich header file declares ntohs() in c++ ?
关于Makefile的一个问题vc 2008: compilation error about header file
最初级的白痴C++问题size of structure
C语言重复定义问题macro and std:: function name clashing
相关话题的讨论汇总
话题: friend话题: header话题: func1话题: seperate
进入Programming版参与讨论
1 (共1页)
l******e
发帖数: 94
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?
l******e
发帖数: 94
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?

p****o
发帖数: 1340
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?

l******e
发帖数: 94
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

d******e
发帖数: 194
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.

1 (共1页)
进入Programming版参与讨论
相关主题
macro and std:: function name clashingforward declaration
tr1,问题关于Makefile的一个问题
how to split function declaration and implementation in C#最初级的白痴C++问题
怎么样最好的编译不同文件在同一个VC project里面?C语言重复定义问题
一道面试怪题C++. (转载)基础问题:在header里面define function
关于C++ STL编译的疑问Qt Creator
请教有关header file的几个问题Question about
ask a question about compile shared library using libtoolHow to see the content of a library file
相关话题的讨论汇总
话题: friend话题: header话题: func1话题: seperate