Okay this is going to be going back to the basics, but its a question about the best way of doing something. I need to call a function in another class. Is the best way to do that just to construct a class object and call the function with the class object like:
someclass.function();
or is there a better way to call the one function I need without tying the 2 classes together.
#include <iostream>
#include <vector>
usingnamespace std;
class calculateAverage{
private:
double total;
public:
double getAverage(vector<double> numbers){
for(int i = 0; i < 10; i++){
total = total + numbers[i];
}
return total / 10;
}
};
to call get average from the application class do I need to construct a calculate class object like I did and the call it or is there another way to call it
In this case, you would need to create an object to call the function. However I'm wondering why you have a class for calculating an average...it seems like it would be better to just have it as a global function or as a member function of application.