Click here to Skip to main content
15,350,817 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new to shared_ptr's and I'm trying to figure out the build error:

error C2664: 'IFD::IFD(const IFD &)' : cannot convert argument 1 from 'IFD *' to 'const IFD &'

It's strange that it's not working because I copied a code section from a similar area that was building.

The affected code looks like this in IFJ.cpp:

void IFJ::addElementVectorIFD(shared_ptr<IFD> rspIFD)
    m_spVectorIFD.push_back(std::make_shared<IFD>(rspIFDocument.get())); //add item to vector

(there's got to be a way to copy/paste into CodeProject without it inserting '"<"' and's not easy to look at)

in IFJ.h:

void addElementVectorIFD(shared_ptr<IFD> rspIFD);
 vector<shared_ptr<IFD>>  m_spVectorIFD; 

I found this link[^] but it's a little different so I'm not sure if I have the same issue.
MichCl 19-Jan-15 9:13am
I tried this too
m_spVectorIFD.push_back(std::shared_ptr<ifd>(new IFD(rspIFD.get()))); //add item to vector and get the same error message as above:

error C2664: 'IFD::IFD(const IFD &)' : cannot convert argument 1 from 'IFD *' to 'const IFD &'

it is the same issue: type mismatch. You construct a temporary pointer, but need a ref type.

Often is the error message correct. Really often... ;-)
MichCl 19-Jan-15 8:57am
Sorry @KarstenK, I'm trying to put a shared pointer into a vector of shared pointers. Why does it think it needs a ref?
MichCl 19-Jan-15 9:07am
I tried this too and it didn't work either: m_spVectorIFD.push_back(rspIFD.get()); //add item to vector

error for that says: "error C2664: 'void std::vector<std::shared_ptr<ifd>,std::allocator<_Ty>>::push_back(const std::shared_ptr<ifd> &)' : cannot convert argument 1 from 'IFD *' to 'std::shared_ptr<ifd> &&'
I wound up just doing this:


After I looked at this link:[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900