Z
Z
zenz2021-10-08 14:52:09
C++ / C#
zenz, 2021-10-08 14:52:09

Visual Studio does not call the function written below the other one (read does not call read_hw), both are declared in the header, how to fix it?

Original file:

bool compare(const Student_info& x, const Student_info& y)
{
  return x.name < y.name;
}

istream& read(istream& is, Student_info& s)
{
  is >> s.name >> s.midterm >> s.final;

  read_hw(is, s.homework);

  return is;
}
istream& read_hw(istream& in, vector<double> hw)
{
  if (in) {
    hw.clear();
    double x;
    while (in >> x)
      hw.push_back(x);
    in.clear();
  }
  return in;
}


Function definition in header:
struct Student_info {
  std::string name;
  double midterm, final;
  std::vector<double> homework;
};

bool compare(const Student_info&, const Student_info&);
std::istream& read(std::istream&, Student_info&);
std::istream& read_hw(std::istream&, std::vector<double>&);
#endif

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-10-08
@zenz

Look carefully, the implementations and declarations of the read_hw function do not match - there are different types of arguments.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question