Seems Document can also be used as parameter in
void test(Value value);
and both Document and Value can have child value, what is the difference between them?
Firstly, the test
function should not compile because Value
does not support copy constructor. So you must use Value& value
or const Value& value)
instead.
Back to the question, Value
represents a node in the DOM. Document
derives from Value
, and it represents the root of the DOM. Document
provides functionality for parsing a JSON into the DOM, while Value
cannot.
If the function does not need to call APIs dedicated for Document
, such as Document::Parse()
, you should use Value&
. Passing a Document
object to Value&
parameter is OK in C++ too.