Call to non-static member function without an object argument compiler error

The error message from the compiler is very clear.

getInput is a non-static member function of the class.

You need an object of the class to be able to use that member function.

Instead of

stats::getInput(std::cin);

use

stats obj;
obj.getInput(std::cin);

Another solution.

Since the class does not have any member variables, you may change getInput to a static member functions.

class stats {

   public:
      stats();
      static std::vector <double> getInput(std::istream& input_stream);

   private:
};

If you do that, you may use:

stats::getInput(std::cin);

Also, your loop to read the data can be simplified to:

while (input_stream >> x){
  stream.push_back(x);
}

Leave a Comment