Boost logo

Boost Users :

Subject: [Boost-users] [test] memory access violation by calling <<-operator
From: M. Siebeneicher (trashing_at_[hidden])
Date: 2008-09-18 05:16:21


Hi boost-users,

I created a class and overload the <<-operator. Now I tried to test them by assigning an instance of the class to an ostringstream, but I get always the error:
"fatal error in "EmptyVertex_output_stream": memory access violation occurred at address 0xcccccce0, while attempting to read inaccessible data"

It's very curious, because assigning a string directly to the ostringstream, no error occurs. I'm using boost 1.35.0 and VS2003

The code:

// test_class.cpp
BOOST_AUTO_TEST_CASE( EmptyVertex_output_stream)
{
        // 1 //
        const string vertexNameIn1 = "test name";
        const EmptyVertex emptyVertex1(vertexNameIn1);
        ostringstream currString1;
        currString1 << emptyVertex1; // Error occurs here, see class_to_test.cpp
        string expString1 = "EmptyVertex(name=test name)";
        BOOST_CHECK_EQUAL(currString1.str(), expString1);
}

//class_to_test.cpp
/*public friend*/ ostream&
operator<<(ostream& streamOut, const EmptyVertex& vertex) {
        streamOut << "EmptyVertex("; // Error occurs here
        streamOut << vertex.getName();
        streamOut << ")";

        return streamOut;
}

Can someone give me a clue?

greetz,
modbom

-- 
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten 
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net