Home » Community » Newbie corner » Value strange behaviour result in ValueTypeError
|
Re: Value strange behaviour result in ValueTypeError [message #51796 is a reply to message #51791] |
Fri, 31 May 2019 23:30 |
Novo
Messages: 1371 Registered: December 2006
|
Ultimate Contributor |
|
|
Your code is throwing an exception.
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00007ffff7a42535 in __GI_abort () at abort.c:79
#2 0x00007ffff7e0b642 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007ffff7e17186 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ffff7e171d1 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007ffff7e17405 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x00005555556109c4 in Upp::Value::GetSmall<long long> (this=0x7ffff7fc85b0) at /home/ssg/dvlp/cpp/upp/git/uppsrc/Core/Value.hpp:209
#7 0x00005555555ae241 in Upp::Value::GetOtherBool (this=0x7ffff7fc85b0) at /home/ssg/dvlp/cpp/upp/git/uppsrc/Core/Value.cpp:203
#8 0x000055555556ca7e in Upp::Value::operator bool (this=0x7ffff7fc85b0) at /home/ssg/dvlp/cpp/upp/git/uppsrc/Core/Value.h:221
#9 0x000055555556d1ed in testAddVector<Upp::String> (keyname=..., t=...)
at /home/ssg/dvlp/cpp/sergey/upp/ValueStrangeBehaviour/ValueStrangeBehaviour.cpp:7
#10 0x000055555556be96 in ConsoleMainFn_ () at /home/ssg/dvlp/cpp/sergey/upp/ValueStrangeBehaviour/ValueStrangeBehaviour.cpp:17
#11 0x000055555558d2dd in Upp::AppExecute__ (app=0x55555556bc76 <ConsoleMainFn_()>) at /home/ssg/dvlp/cpp/upp/git/uppsrc/Core/App.cpp:343
#12 0x000055555556bc69 in main (argc=1, argv=0x7fffffffdf18, envptr=0x7fffffffdf28)
at /home/ssg/dvlp/cpp/sergey/upp/ValueStrangeBehaviour/ValueStrangeBehaviour.cpp:12
This is happening in this statement:
if(ConfigurationType.Add()) //Add t to value
because you are adding a String, which will be returned by the method Add(), and you are trying to implicitly convert Value, containing this string, to bool in the if() statement.
Such conversion is impossible. This is why you are getting an exception.
Regards,
Novo
|
|
|
Re: Value strange behaviour result in ValueTypeError [message #51797 is a reply to message #51791] |
Sat, 01 June 2019 11:32 |
Oblivion
Messages: 1112 Registered: August 2007
|
Senior Contributor |
|
|
Hello Xemuth,
Novo is right.
You are implicitly trying to convert a string "Value" to bool, which is not possible that way.
VectorMap<String, String> ConfigurationType;
template <class T>
bool testAddVector(String keyname, const T& t)
{
ConfigurationType.Add(keyname, t); // You have implicitly tried to convert a string "Value" into a bool "Value" (hence the "Value" error)
return true;
}
ValueMap vmap;
void TestValueMap(Value key, Value val) // Just change the key's signature to String if you want to limit the key type...
{
vmap.Add(key, val);
}
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
String s = "world";
testAddVector("Hello", s);
DUMP(ConfigurationType.ToString());
// If possible, I suggest using a ValueMap.
TestValueMap("Hello", "World");
TestValueMap(1, "This is a test");
TestValueMap("This is a test too!", 2);
DUMP(vmap);
}
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Sat, 01 June 2019 11:36] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Fri Sep 20 03:47:16 CEST 2024
Total time taken to generate the page: 0.02625 seconds
|