[英]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. 我愿意用SDL制作2D游戏,并且遵循Shaun Mitchell的书。 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? 到TiXmlString类中的tinyxmlstr.h? If so, how to implement it?
如果是这样,如何执行呢? What should I return?
我应该退还什么?
If I don't define the STL (which I use) in tinyxml.h, the compiler then returns a linkage error. 如果我未在tinyxml.h中定义STL(我使用的STL),则编译器将返回链接错误。
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)
StateParser class and implementation is the same as the one in the book. StateParser的类和实现与本书中的相同。
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 &
. 错误很明显:不可从
const TiXmlString
转换为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
根据此页面 ,如果我没看错,甚至没有从
TiXmlString
到std::string
的直接转换。
I suppose you can write a method like this (exactly like the value()
that return a const char *
) 我想您可以编写一个这样的方法(就像返回
const char *
的value()
一样)
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. 但是以这种方式,您返回
value
的副本(因此,返回const std::string
,而不是简单的std::string
,是没有用的),而不是引用。 I don't know if this it's OK for you. 我不知道这是否适合您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.