Actions
Support #8402
closedJson::Array cast problem
Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
04/22/2021
Due date:
% Done:
0%
Estimated time:
Description
Hello,
Using Wt 4.5.0, I have a Json::Value that I want to be converted into an Array:
void parseValue(const Wt::Json::Value& value)
{
switch (value.type())
{
case Wt::Json::Type::Array:
{
const Wt::Json::Array& array {static_cast<const Wt::Json::Array&>(value)}; // works fine
// const Wt::Json::Array& array {value}; // returns an array of size 1, which contains itself an array of size 1 (if using the same inner cast), etc.
...
Maybe I missed something in your cast operators and constructors, but not explicitly casting here leads to very weird questionable behaviors.
Updated by Korneel Dumon about 3 years ago
Hi Emeric,
I think this is more of a c++ pitfall than an api error. The initializer list constructor takes precedence over implicit conversion. The problem goes away if you use round braces. Even better is to use assignment, since this avoids creation of a temporary object:
const Wt::Json::Array& array = value;
Updated by Emeric Poupon about 3 years ago
Hello!
Ah I missed this constructor indeed!
Ok I understand your point then.
Updated by Roel Standaert about 3 years ago
- Tracker changed from Bug to Support
- Status changed from New to Closed
Actions