🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.migration
3 messages
3 total messages Started by Gene Thu, 26 Jun 2008 07:27
BCB6 project to CB2007 problem.
#111
Author: Gene
Date: Thu, 26 Jun 2008 07:27
18 lines
1389 bytes
Hi, 
 I have got a compiling error saying "[BCC32 Error] switch1.cpp(40): E2034 Cannot convert 'std::_Vector_iterator<std::string,std::allocator<std::string> >' to 'std::string *'"
The code is as in below:

  std::vector<std::string> StringList;
  for (int i = 0; i < 10; i++) {
    StringList.push_back(IntToStr(i).c_str());
  }
  std::vector<std::string>::iterator it=StringList.begin();
  std::string* ctmp=it;
  ShowMessage(ctmp->c_str());

  It compiles ok in BCB6, but it is an error in C++ Builder 2007. Is it any compilation options I set wrong? Or C++ Builder 2007 is a lot stricter in grammar than BCB6? Can anyone give me help on this?

Thanks.

Gene.
Re: BCB6 project to CB2007 problem.
#112
Author: Leo Siefert
Date: Thu, 26 Jun 2008 13:53
27 lines
1796 bytes
Gene wrote:

>Cannot convert std::_Vector_iterator<std::string> to std::string *

You are attempting to do something that is dependent upon the
implementation of the STL. a vector iterator is allowed by the
standard to be an array pointer, but it does not have to be one. There
is nothing in the standard that allows this type of conversion.

This worked in BCB6 because that used a different STL which used
pointers as vector iterators, and does not work in CB2007 because it
uses a different STL.

Since this is an implementation dependent detail, you are best to use
code that does not rely on it. Either use vector<>::iterator as your
function parameters, etc. or convert to a pointer if necessary like
this:

	&*TheIterator;

In the code you posted, you can simply use the iterator itself with
pointer syntax (iterators to have * and -> implemented like pointers
do):

  ShowMessage(it->c_str());

 - Leo
Re: BCB6 project to CB2007 problem.
#113
Author: Gene
Date: Thu, 26 Jun 2008 14:45
6 lines
921 bytes
It works!

Thank you! Leo.

Gene
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads