Answer the question
In order to leave comments, you need to log in
How to make constructor overload without type extension?
We have two variations of the class constructor:
CAttribute(const string &name, const uint32_t index, const CSiiData &value);
CAttribute(const string &name, const bool hasIndex, const CSiiData &value);
there is more than one instance of the "CAttribute::CAttribute" constructor corresponding to the list of arguments:
the function "CAttribute::CAttribute(const std::string &name, uint32_t index, const std::string &value)"
the function "CAttribute::CAttribute(const std ::string &name, bool hasIndex, const std::string &value)"
argument types: (const char [12], int, const char [5])
attr: value
attr[0]: some_value
attr[1]: some_value2
attr[]: some_value
attr[]: some_value2
Answer the question
In order to leave comments, you need to log in
I would leave in general one view constructor
Negative indexes are treated as "Unnumbered" attributes.
This happens due to the expansion of the bool type to int
int
can be reduced both to bool
and to uint32_t
. And the compiler doesn't know what exactly you mean. It is enough to explicitly cast the argument to the desired type so that you can unambiguously determine which constructor you are calling.CAttribute("name", (uint32_t)index, "value");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question