开发者

C++: How to pass results from one class to another class?

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 & calcu开发者_如何学运维lation.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


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.


The definition for data goes in data.h

class Data { ... }

and include the file in analysis.cpp

#include "data.h"

and pass it as a reference

class Analysys { bool Analyse(Data &data); }


You can create new structure in which you can store results from your class and use it to send your results over your classes. For example:

Struct Result {
    bool dataResult;
    bool analisysResult;
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜