首页 > 其他分享 >友元的使用

友元的使用

时间:2022-09-26 22:36:40浏览次数:44  
标签:友元 semiGlobalMatching height SemiGlobalMatching width 使用 Grad

最近在做Census变换的项目中,在原先的代码基础上添加了一个计算梯度的文件,文件中新建了一个Grad类,但是又不想重新开辟内存(感觉会节省空间)想直接使用SemiGlobalMatching中的成员属性

/** \brief 影像宽 */
sint32 width_;

/** \brief 影像高 */
sint32 height_;

于是用到了友元;

先在grad_compute.h文件中声明一个SemiGlobalMatching类型的类指针(写在Grad的private中)

 1 SemiGlobalMatching* semiGlobalMatching; 

然后在SemiGlobalMatching.h中声明这个友元

 1 friend class Grad; 

最后grad_compute.cpp里面就可以使用SemiGlobalMatching中的成员属性啦!哈哈ヾ(≧▽≦*)o

1 //在堆区开辟一个SemiGlobalMatching类
2 semiGlobalMatching = new SemiGlobalMatching;
3 auto hight = semiGlobalMatching->height_;
4 auto width = semiGlobalMatching->width_;
5 angle = new float32[(hight - 2) * (width - 2)];

 

标签:友元,semiGlobalMatching,height,SemiGlobalMatching,width,使用,Grad
From: https://www.cnblogs.com/Sandals-little/p/16732775.html

相关文章