无法从const TiXmlString转换为const std :: string& [英] Cannot convert from const TiXmlString to const std::string&
问题描述
我愿意用SDL制作一个2D游戏,我跟着Shaun Mitchell的书。但是在尝试编译我的项目时,我遇到了这个用户定义的类型转换错误的严重困难...
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.
我需要添加
operator std::string&() const { return ???;}
到TiXmlString类中的tinyxmlstr.h?如果是这样,怎么实现呢?我应该返回什么?
to the tinyxmlstr.h in TiXmlString class? If so, how to implement it? What should I return?
如果我没有在tinyxml.h中定义STL(我使用它),编译器会返回一个链接错误。
If I don't define the STL (which I use) in tinyxml.h, the compiler then returns a linkage error.
错误19错误LNK2019:未解析的外部符号public:virtual __cdecl TiXmlNode ::〜TiXmlNode(void)(?? 1TiXmlNode @@ UEAA @ XZ) public:virtual __cdecl TiXmlDocument ::〜TiXmlDocument(void)(?? 1TiXmlDocument @@ UEAA @ XZ)
StateParser类和实现是
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!
推荐答案
错误很清楚: const TiXmlString
const std :: string&
。
根据此页 ,如果我没有错,甚至没有直接从 TiXmlString
转换为 std :: string
According to this page, if I'm not wrong, there isn't even a direct conversion from TiXmlString
to a std::string
我想你可以写这样的方法(就像 value()
,返回一个 const char *
)
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(); }
但是这样你会返回 value
(因此返回一个 const std :: string
,而不是一个简单的 std :: string
,不是参考。我不知道这是不是可以为你。
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.
这篇关于无法从const TiXmlString转换为const std :: string&的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!