CFanatic

Go Back   CFanatic > Programming > C++ Programming

Join CFanatic Forum Now

Error passing a value_type as a reference topic posted under C++ Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 08-15-2008, 10:40 PM
Junior Member
 
Join Date: Jul 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
a_new_beginning is on a distinguished road
| More
Error passing a value_type as a reference

The code I have posted below compiles and runs fine, but the problem is the value_type passed into the parameter of the map_insert function must be copied.
I'm having difficulty passing it by reference. I have tried using the following:

"string_svector_map::reference vecPair_in"
and also
"string_svector_map::value_type &vecPair_in",

Both result in a compile-time error. I am confused why these do not work.
Can anyone alter this so that the value_type can be passed by reference?
Code:
using namespace std;

typedef map<string, vector<pair<string, string> > > string_svector_map;

string_svector_map::const_iterator map_insert(string_svector_map &map_in, string_svector_map::value_type vecPair_in){ 	

	pair<string_svector_map::const_iterator, bool> insert_result (map_in.insert(vecPair_in));

	bool &inserted (insert_result.second);

	if(!inserted){
		throw runtime_error("Error inserting a pair into the map_in map....exiting program");
		exit(0);
	}
	else
		return insert_result.first;
}


int main(){

	string s1 ("Hello"),
				 s2 ("World!"),
				 s3 ("help!");

	string_svector_map the_map;
	vector<pair<string, string> > the_vec;

	the_vec.push_back(make_pair (s1, s2));

	string_svector_map::const_iterator insert_result = map_insert(the_map, string_svector_map::value_type(s3, the_vec)); 

	return 0;
}

Last edited by a_new_beginning; 08-15-2008 at 10:46 PM.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
passing arrays in C# Xarzu C# Programming 3 09-29-2008 05:27 AM
query about reference kishore C++ Programming 3 06-29-2008 09:31 AM
Some good article on reference kishore C Programming 1 05-27-2008 04:03 AM
#1 Tutorial/Reference for GDI+ using C++ MartijnMulder C++ Programming 2 09-03-2007 09:27 PM
code on passing array from MFC ActiveX to Jscript... 冯锦华 MFC Programming 0 06-27-2007 02:34 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 03:29 PM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board