Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error returning a pair in cpp

I have the following code:

 return new std::pair<BST<Data>::iterator(cursor), true>;

This results in the following errors:

could not convert '(operator new(4u), (, ((int*))))' from 'int*' to 'std::pair, bool>'
type/value mismatch at argument 1 in template parameter list for 'template struct std::pair'

What might be the problem here?


1 Answers

Apart from the new (don't use new unless you have to) and return, in order to construct a pair, use either the mentioned make_pair() function or invoke the constructor like this: pair<T1, T2>(v1, v2). You were mixing up the type (pair<T1, T2>) with the values to init that type's instance (v1, v2).

like image 115
Ulrich Eckhardt Avatar answered May 10 '26 12:05

Ulrich Eckhardt