随笔 - 226,  文章 - 0,  评论 - 4,  阅读 - 30326
最近在做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)];

 

posted on   小凉拖  阅读(21)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示