This commit is contained in:
nlohmann committed 2026-10-12 07:35:31 +00:00
1 parent 79119509a9
commit 22fba27145
555 files changed
+17342 -1394

No files matched your search

+33 -2
View File
@@ -35,13 +35,44 @@ The function is equivalent to `static_cast<json_base_class_t&>(j)` (or `static_c
of `basic_json`.
```cpp
--8<-- "examples/as_base_class.cpp"
#include <iostream>
#include <nlohmann/json.hpp>
class base_class_with_hidden_members
{
public:
const char* type_name() const noexcept
{
return "my_type_name";
}
std::size_t size() const noexcept
{
return 42;
}
};
using json = nlohmann::json::with_base_class_t<base_class_with_hidden_members>;
int main()
{
json j = {1, 2, 3};
// the members of basic_json hide the members of the base class
std::cout << j.type_name() << ' ' << j.size() << '\n';
// access the hidden members of the base class
std::cout << j.as_base_class().type_name() << ' ' << j.as_base_class().size() << '\n';
}
```
Output:
```json
--8<-- "examples/as_base_class.output"
array 3
my_type_name 42
```
## See also