STL pair

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Post Reply
Lena
BCBJ Master
BCBJ Master
Posts: 709
Joined: Sun Feb 06, 2011 1:28 pm

STL pair

Post by Lena »

Hello.
How to compile a project created in BCB6 for BCB2007.
Please tell me how to fix the error for BCB2007:

Code: Select all

//cpp
TMMint Sort;
    for(int i=1;i<StringGrid2->RowCount;i++)
    {
        Sort.insert(TMMint::value_type(StrToInt(StringGrid2->Cells[3][i]),StringGrid2->Cells[1][i]));//error
    }

Code: Select all

//h
typedef multimap<int, AnsiString> TMMint; 
Could not find a match for 'pair<const int,AnsiString>::pair(AnsiString,AnsiString)'
Lena
BCBJ Master
BCBJ Master
Posts: 709
Joined: Sun Feb 06, 2011 1:28 pm

Re: STL pair

Post by Lena »

Error disappeared after:

Code: Select all

	TMMint Sort;
    for(int i=1;i<StringGrid2->RowCount;i++)
	{
	  int value = StrToInt(StringGrid2->Cells[3][i]);  // <---
	  Sort.insert(TMMint::value_type(value, StringGrid2->Cells[1][i]));// Ok
	}
rlebeau
BCBJ Author
BCBJ Author
Posts: 1726
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA
Contact:

Re: STL pair

Post by rlebeau »

Lena wrote:

Code: Select all

        Sort.insert(TMMint::value_type(StrToInt(StringGrid2->Cells[3][i]),StringGrid2->Cells[1][i]));//error
Could not find a match for 'pair<const int,AnsiString>::pair(AnsiString,AnsiString)'
The code you showed originally is perfectly fine, so I don't know why the compiler would think you are trying to pass an AnsiString in the value_type constructor's 1st parameter when you are clearly passing an int instead. But, you can try using the std::make_pair() function instead of constructing the value_type directly:

Code: Select all

Sort.insert(std::make_pair(StringGrid2->Cells[3][i].ToInt(), StringGrid2->Cells[1][i]));
Remy Lebeau (TeamB)
Lebeau Software
Lena
BCBJ Master
BCBJ Master
Posts: 709
Joined: Sun Feb 06, 2011 1:28 pm

Re: STL pair

Post by Lena »

Thank you veru much!
std:: make_pair works fine.
Post Reply