Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » VectorMap<String,String> = Seg Fault  () 1 Vote
VectorMap<String,String> = Seg Fault [message #28108] Tue, 17 August 2010 07:32 Go to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
I have the following program which I believe should work:


#include <Core/Core.h>

using namespace Upp;

CONSOLE_APP_MAIN
{
	VectorMap<String,String> map;
	map.Put("A", "B");
	map.Put("C", "D");
	map.Put("E", "F");
	
	Vector<String> keys = map.GetKeys();
	for (int i = 0; i < keys.GetCount(); i++)
		Cout() << map.Get(keys[i]) << "\n";
}


however, it fails with the exception:

Assertion failed in /home/jeremy/upp/svn/uppsrc/Core/Vcont.h, line 33
i >= 0 && i < items

Segmentation fault


Any thoughts?

Jeremy
Re: VectorMap<String,String> = Seg Fault [message #28110 is a reply to message #28108] Tue, 17 August 2010 08:31 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Hello Jeremy

Doing this has been quite aggresive Smile

Vector<String> keys = map.GetKeys();


Vector class has not any copy constructor.

It would work this:

Vector<String> keys;
keys <<= map.GetKeys();


Or much better, this:

const Vector<String> &keys = map.GetKeys();


Best regards
Iñaki
Re: VectorMap<String,String> = Seg Fault [message #28119 is a reply to message #28108] Tue, 17 August 2010 16:25 Go to previous messageGo to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
Thanks. That does work, however, shouldn't the other work as well? I will not use it knowing what I know now but just curious.

I'll have to start paying more attention to what has and what doesn't have a copy constructor.

Jeremy
Re: VectorMap<String,String> = Seg Fault [message #28122 is a reply to message #28108] Tue, 17 August 2010 17:58 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

This particular case with GetKeys() (and GetValue() too) is quite tricky for new users... I was fighting with it quite often myself. Even when I became aware of the pick behaviour and I was watching my steps carefully, this one always escaped my attention. I guess it is because it seems to human brain that you are getting some newly created Vector of keys, but internally it really works with the actual keys.

Maybe we should mention this in U++ traps and pitfalls...

Honza

[Updated on: Tue, 17 August 2010 17:59]

Report message to a moderator

Re: VectorMap<String,String> = Seg Fault [message #28125 is a reply to message #28122] Tue, 17 August 2010 21:01 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
A small trick has been that this

Quote:

Vector class has not any copy constructor


MinGW did not tell it but MSC yes Razz


Best regards
Iñaki
Re: VectorMap<String,String> = Seg Fault [message #28412 is a reply to message #28125] Wed, 01 September 2010 08:28 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Tue, 17 August 2010 15:01

A small trick has been that this

Quote:

Vector class has not any copy constructor


MinGW did not tell it but MSC yes Razz


Which is only because MSC does not conform to C++ standard... :-\
Previous Topic: Problem. How to convert AttrText to String?
Next Topic: Problem and fix in HexString
Goto Forum:
  


Current Time: Thu Apr 18 04:58:45 CEST 2024

Total time taken to generate the page: 0.02642 seconds