I have the following code which is giving me this error
main.cpp(41): error C2664: 'std::pair std::make_pair(_Ty1,_Ty2)' : cannot convert argument 1 from 'Handle' to 'unsigned int &'
My example program is
#include <vector>
#include <utility>
typedef unsigned int u32;
typedef u32 Handle;
struct File
{
File()
: ch(0),
pageIdx(0)
{
}
Handle ch : 8;
u32 pageIdx;
};
int main() {
std::vector<std::pair<Handle, u32> > toTrim;
toTrim.reserve(64);
File* m_pFirstPage = new File();
File* pRef = m_pFirstPage;
toTrim.push_back(std::make_pair(pRef->ch,pRef->pageIdx));
return 0;
}
When I try to static cast i.e
toTrim.push_back(std::make_pair(static_cast<unsigned int>(pRef->ch), pRef->pageIdx));
I get the following error
main.cpp(41): error C2664: 'std::pair std::make_pair(_Ty1,_Ty2)' : cannot convert argument 1 from 'unsigned int' to 'unsigned int &'
Can someone please help me resolve it and explain what I am doing wrong.
static_cast
works fine for me on GCC 5, what compiler are you using? – user657267