简体   繁体   中英

Cannot convert from const TiXmlString to const std::string&

I am willing to make a 2D game with SDL and I am following a Shaun Mitchell's book. But I faced serious difficulties with this user-defined type conversion error when trying to compile my project...

Also, I am unfamiliar with this topic. I've watched some tutorials and searched the web for a solution.

Do I need to add

operator std::string&() const { return ???;}

to the tinyxmlstr.h in TiXmlString class? If so, how to implement it? What should I return?

The Errors

If I don't define the STL (which I use) in tinyxml.h, the compiler then returns a linkage error.

Error 19 error LNK2019: unresolved external symbol "public: virtual __cdecl TiXmlNode::~TiXmlNode(void)" (??1TiXmlNode@@UEAA@XZ) referenced in function "public: virtual __cdecl TiXmlDocument::~TiXmlDocument(void)" (??1TiXmlDocument@@UEAA@XZ)

Without STL

StateParser class and implementation is the same as the one in the book.

Finally, if I have a mistake somewhere, how to debug it properly and where to look for it? Thank you, in advance!

The error is clear: non conversion available from const TiXmlString to const std::string & .

According to this page , if I'm not wrong, there isn't even a direct conversion from TiXmlString to a std::string

I suppose you can write a method like this (exactly like the value() that return a const char * )

std::string valueStr () cont 
 { return value.c_str(); }

but in this way you return a copy of value (so return a const std::string , instead a plain std::string , is useless), not a reference. I don't know if this it's OK for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM