C ++:如何将结果从一个类传递到另一个类?

编程入门 行业动态 更新时间:2024-10-28 09:22:41
本文介绍了C ++:如何将结果从一个类传递到另一个类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个类来读取数据(data.h& data.cpp),一个类用于分析数据(analysis.h& analysis.cpp),另一个类基于两个以前的类进行计算(计算。 h& calculation.cpp)。 我不知道如何将结果从数据类传递给分析类,以后从两者传递到计算类。我试图把data.h放入analysis.cpp但它没有成功谢谢你的时间

I have one class to read data (data.h & data.cpp), one class to analysis data (analysis.h & analysis.cpp) and another one to do calculation based on two previous classes (calculation.h & calculation.cpp). I wonder how can I pass the results from data class to analysis class and later on from both of them to calculation class. I tried to put the data.h into analysis.cpp but it didn't work out Thank you for your time

推荐答案

在calculate.cpp中,您可以#include data.h和analysis.h,然后使用数据函数检索数据,将结果传递给分析,然后将这些结果计算。

In calculation.cpp, you'd #include data.h and analysis.h, then use data functions to retrieve the data, passing the result(s) to analysis, then those results to calculation.

这可以归结为大致像... ...

This boils down to something roughly like...

#include "data.h" #include "analysis.h" Data data; Analysis analysis; while (data.get()) analysis.process_more(data); Calculation calculation(analysis); calculation.report();

换句话说,类类型的对象是结果。

In other words, objects of the class types ARE the results.

更多推荐

C ++:如何将结果从一个类传递到另一个类?

本文发布于:2023-11-25 14:28:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630123.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!