Click here to Skip to main content
15,879,474 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:

C++
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:

XML
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 such...it's not easy to look at)

in IFJ.h:

C++
public:
void addElementVectorIFD(shared_ptr<IFD> rspIFD);
private:
 vector<shared_ptr<IFD>>  m_spVectorIFD; 


I found this link http://stackoverflow.com/questions/22390854/error-c2664-cannot-convert-argument-from-nodeint-to-int[^] but it's a little different so I'm not sure if I have the same issue.
Posted
Comments
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 &'

I wound up just doing this:

m_spVectorIFDocument.push_back(rspIFDocument);

After I looked at this link: http://stackoverflow.com/questions/6081556/c-stdvectorstdshared-ptr[^]
 
Share this answer
 
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... ;-)
 
Share this answer
 
Comments
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> &&'
"

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