VTK VisualStudio2013 Compile Error

c++, visual-studio-2012, vtk

Solution

I've got exactly the same errors when building VTK 5.8.0 in Win 8.1 + VS2013x64.

Here's my solution:

After substituting the macros, the error goes to the definition of `operator<<`. The compiler need to find an declaration that matches

this->ostr << a;

where the type of `this->ostr` and `a` are both `std::ostream &`. So I wrote a simple test code to check the VS compiler.

#include <iostream>
#include <sstream>

void test(std::ostream &a, std::ostream &b) {
    a << b;
}

int main(int argc, char *argv[])
{
    std::ostringstream a,b;
    test(a,b);
    std::cout << a << std::endl;
    return 0;
}

It turns out to be correct on GCC4.7. And seems that `ostream` is auto-casted to some kind of a pointer (not its own address, but it doesn't matter, just output an address). However, VS2013 gives me the same error as building VTK! So, let's make rewrite the definition of `vtkOStreamWrapper::operator<< (ostream &a)`:

//VTKOSTREAM_OPERATOR(ostream&);
vtkOStreamWrapper& vtkOStreamWrapper::operator << (ostream& a) {
    this->ostr << (void *)&a;
    return *this;
}

Since the code

if ( this->IFile->read(result, 80) == 0)

actually is a C++11 way to determine whether `ifstream->read()` suceeds or not (a `ostream` can be auto-casted to a `bool`), which is not supported by VS2013. I change all of them into standard form:

if ( this->IFile->read(result, 80).fail())

Problem

I'm trying to compile VTK5.10.1 in windows7 and Visual Studio2013( vs2012 C++ compiler, so I guess somebody may face the same question in 2012) After fix some small bug and some missing head file Follow the tuitols of the VTK wiki. IN THE LAST STEP: I got two error - C2678: binary '<<' : no operator found which takes a left-hand operand of type 'std::ostream' (or there is no acceptable conversion) #define VTKOSTREAM_OPERATOR(type) \ vtkOStreamWrapper& vtkOStreamWrapper::operator << (type a) \ { this->ostr << a; return *this; } ``` VTKOSTREAM_OPERATOR(ostream&); ``` 2.binary '==' : no operator found which takes a left-hand operand of type 'std::basic_istream>' (or there is no acceptable conversion) ``` if ( this->IFile->read(result, 80) == 0) ``` Here the source code tray to run operator== between std :: basic_istream> and int But int the std::istream the operator== is not override. Waiting for help. Thanks

Original source