Aleks G
Aleks G

Reputation: 57316

Invalid arguments in method call

In my class InVal, I have a method and a friend operator declared as below:

void Parse(std::istream& file) throw (int);
friend std::istream& operator >> (std::istream& is, const InVal& id3);

The friend operator >> code is this:

std::istream& operator >> (std::istream& is, const InVal& val) {
    val.Parse(is);
    return is;
}

On the line val.Parse(is) I'm getting Invalid arguments with candidate offer being void Parse(std::basic_istream<char, std::char_traits<char>>&). In iosfwd, I have

typedef basic_istream<char>         istream

So somewhere something isn't matching. Why am I getting the error and how can I resolve it?

Upvotes: 0

Views: 1588

Answers (1)

Joseph Mansfield
Joseph Mansfield

Reputation: 110668

val is a const reference, which means that you can only call const member functions on it. You need to declare Parse as a const member function like so:

void Parse(std::istream& file) const throw (int);

This promises the compiler that Parse will not modify the InVal object it is being invoked on.

Upvotes: 2

Related Questions