C ++:如何将结果从一个类传递到另一个类? [英] C++: How to pass results from one class to another class?

查看:417
本文介绍了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 ++:如何将结果从一个类传递到另一个类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆