Re: Problem with STL vector on Panther 10.3.1
Re: Problem with STL vector on Panther 10.3.1
- Subject: Re: Problem with STL vector on Panther 10.3.1
- From: Christopher Corbell <email@hidden>
- Date: Thu, 13 Nov 2003 14:26:41 -0800
On Nov 13, 2003, at 8:41 AM, Ryan Wilcox wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 11/13/03, at 4:33 PM, email@hidden said:
Hello,
I encountered a strange problem I have been unable to resolve.
Apparently
the following code segment doesn't work at all for me:
int main (int argc, const char * argv[]) {
set< CLabelPoint > spt;
vector< CLabelPoint > cpt;>
cpt.insert( cpt.begin(), lp ); // Here SIGSEGV
}
I had problems with Codewarrior and vectors too (except in my case
data stored
in the vector wasn't there when I went looking for it). I found that
initializing my vector to a certain size solved my problem.
[....]
Hope this helps,
_Ryan Wilcox
No, you do not need to reserve a size for std::vector before
using it. And FWIW CodeWarrior's STL implementation has always
been very good. GCC 3 was a big step forward, I haven't read the
release notes for 3.3, though in general I will say that XCode
seems by default worse than ProjectBuilder about reporting errors
and warnings for standard C++ library and language stuff - not
sure how much of this is gcc change and not XCode.
Anyhow, there is something going else with your code or build
settings. For one thing you have an extra '>' character at the
end of your vector declaration as copied above.
Also your description of CLabelPoint sounds straightforward,
but often errors can occur with class objects stored by-value
if they don't copy fields correctly (since the vector will
be making copies of your object as needed). For instance if
your object contained any pointer fields that might not get
copied or might become stale, use in a vector could cause
a crash.
Otherwise your insert call should work. Note that in general
you should insert and remove from the end of a vector, not the
beginning, for performance reasons. If you need to frequently
insert or remove anywhere but the back consider using std::list
or std::deque. push_back should also work fine, I suspect it's
the extra character in your code or some similar issue. You may
want to go to the project language settings and turn on more
C++ warnings (though when I tried to turn on the "Effective C++"
warnings I got a compiler error that the setting was unknown, and
had to turn it back off).
- Christopher
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.