Ambiguity while moving seekg()

I am having the followimg warning on Dev-C++.

[Warning] ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:

fout.seekg(fout.tellg()-sizeof(ah);

ah is an object of a class.
fout is an object of fstream in ios::out mode

I am moving the pointer to a particular position to edit.
Last edited on
1
2
// seek to -std::streampos{sizeof ah} bytes before the current input position
foo.seekg(-std::streampos{sizeof ah}, std::ios::cur);


fout.tellg() is a std::fpos<std::mbstate_t>, not an integral type.
It supplies sum and difference operators (member functions) that accept a std::streamoff, which is some signed integral type. The ambiguity is between that operator-() and the built-in binary operator-.

You can use the two-argument version of seekg(). Be careful: sizeof returns an unsigned number; negating it will yield a large positive value.
Last edited on
Topic archived. No new replies allowed.