Archived

This topic is now archived and is closed to further replies.

broken code in VC++7

This topic is 5585 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm tryin to change over to VC++7, but I'm running into problem compiling what would normally compile fine in VC++6. example:
XML_Parse(const char *s, int len);

parse(const std::vector<char> &buffer)
{
  XML_Parse(buffer.begin(),buffer.size())
}

   error output:
   e:\projects\UI\xml.cpp(358): error C2664: 'XML_Parse' : cannot                  
   convert parameter 1 from 'std::vector<_Ty,_Ax>::const_iterator'   
   to 'const char *'
        with
        [
            _Ty=char,
            _Ax=std::allocator<char>
        ]

- also -
std::vector<char> buf;
FILE *file = fopen( fileName.c_str(),"rb" );
fread( buf.begin(),fileSize,1,file );

gets this error:

   e:\projects\UI\xml.cpp(386): error C2664: 'fread' : cannot 
   convert parameter 1 from 'std::vector<_Ty,_Ax>::iterator' to 
   'void *'
        with
        [
            _Ty=char,
            _Ax=std::allocator<char>
        ]

  
how does this make any sense? How do I fix it? thanks. EDIT by ze: Fixed your template ><'s just 'cause I got bored... [edited by - zealouselixir on August 27, 2002 10:26:45 PM]

Share this post


Link to post
Share on other sites
Iterators are not guaranteed to be pointers, and vector''s elements are not guaranteed to be stored contiguously. You might be able to get away with it, though. Just use &buffer [0] instead of buffer.begin (). And...uh...you didn''t hear it from me, OK?

Share this post


Link to post
Share on other sites
vectors not contigous ??
i thought vectors had to be contigous ?? Oh oh , my old code in vc6 will surely break like this. damn you microsoft.. damn you..!!!!!

Its my duty, to please that booty ! - John Shaft

Share this post


Link to post
Share on other sites
The Standard doesn''t explicitely state that vectors use contiguous storage, but this is supposed to be fixed in the next publication.

However, in practice, they are, and &buffer[0] gives you a C-compatible pointer to the first element.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

Share this post


Link to post
Share on other sites