Error: 2 overloads have similar conversions

Hey guys,

I am getting this error, error C2666 where it states that 2 overloads have similar conversions. I am not quite sure how to resolve this error, I have looked all over the internet. This is the code I am trying to build.

Here is a copy of the error:

Error 1 error C2666: 'std::fpos<_Statetype>::operator !=' : 2 overloads have similar conversions c:\users\larry\documents\visual studio 2012\projects\test\test\main.cpp 15 1 test


#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

const int rowNum = 14;
const int colNum = 17;
short array[rowNum][colNum];

void readFile( string filename, short* buffer, int rows, int columns )
{
ifstream infile;
infile.open( filename.c_str(), ios::binary | ios::in | ios::ate );
if ( infile.tellg() != 2*rowNum*colNum )
{
cerr << infile.tellg() << " is not " << 2*rows*columns << endl;
exit( -1 );
}
infile.seekg( 0 );
infile.read( (char*) buffer, 2*rows*columns );
infile.close();
}

int main()
{
readFile( "sample.bin", array[0], rowNum, colNum );
for ( int i=0; i<rowNum; i++ )
{
for ( int j=0; j<colNum; j++ )
cout << setw(4) << array[i][j];
cout << endl;
}
}

Can anyone point out what exactly my problem is?, when I run this code in UNIX it doesnt seem to complain about this != issue.
Welcome to the forum. Please use the code tag to format your code.

I compiled it under GCC, and it complained about your use of exit(). You need to include stdlib.h as you don't define it. That aside, it was fine.

I compiled it under Visual Studio and I got your error. You only looked at part of the error. You really ought to read the whole thing.

It says:
x.cc(17) : error C2666: 'std::fpos<_Statetype>::operator !=' : 2 overloads have similar conversions
        with
        [
            _Statetype=_Mbstatet
        ]
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\iosfwd(107): could be 'bool std::fpos<_Statetype>::operator !=(const std::fpos<_Statetype> &) const'
        with
        [
            _Statetype=_Mbstatet
        ]
        or       'built-in C++ operator!=(std::streamoff, int)'
        while trying to match the argument list '(std::fpos<_Statetype>, const int)'
        with
        [
            _Statetype=_Mbstatet
        ]


And that means it doesn't know what to do with 2*rowNum*colNum. For some reason it cannot compare a streampos with an int as there's more than one way to do it. That's really annoying, I'm not sure it's right.

I fixed it as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <iomanip>
#include <fstream>

#include <stdlib.h>

using namespace std;

const int rowNum = 14;
const int colNum = 17;
short array[rowNum][colNum];

void readFile( string filename, short* buffer, int rows, int columns )
{
        ifstream infile;
        infile.open( filename.c_str(), ios::binary | ios::in | ios::ate );
        std::streamoff mx = 2*rowNum*colNum;
        std::streamoff pos = infile.tellg();
        if ( pos != mx )
//      if ( infile.tellg() != 2*rowNum*colNum )
        {
                cerr << infile.tellg() << " is not " << 2*rows*columns << endl;
                exit( -1 );
        }
        infile.seekg( 0 );
        infile.read( (char*) buffer, 2*rows*columns );
        infile.close();
}

int main()
{
        readFile( "sample.bin", array[0], rowNum, colNum );
        for ( int i=0; i<rowNum; i++ )
        {
                for ( int j=0; j<colNum; j++ )
                        cout << setw(4) << array[i][j];
                cout << endl;
        }
}
Last edited on
Topic archived. No new replies allowed.