mirror of
https://github.com/nlohmann/json.git
synced 2026-04-07 00:28:56 +00:00
deploy: 26cfec34be
This commit is contained in:
37
examples/nlohmann_define_derived_type_intrusive_macro.cpp
Normal file
37
examples/nlohmann_define_derived_type_intrusive_macro.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
class A
|
||||
{
|
||||
private:
|
||||
double Aa = 0.0;
|
||||
double Ab = 0.0;
|
||||
|
||||
public:
|
||||
A() = default;
|
||||
A(double a, double b) : Aa(a), Ab(b) {}
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(A, Aa, Ab)
|
||||
};
|
||||
|
||||
class B : public A
|
||||
{
|
||||
private:
|
||||
int Ba = 0;
|
||||
int Bb = 0;
|
||||
|
||||
public:
|
||||
B() = default;
|
||||
B(int a, int b, double aa, double ab) : A(aa, ab), Ba(a), Bb(b) {}
|
||||
NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE(B, A, Ba, Bb)
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
B example(23, 42, 3.142, 1.777);
|
||||
json example_json = example;
|
||||
|
||||
std::cout << std::setw(4) << example_json << std::endl;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"Aa": 3.142,
|
||||
"Ab": 1.777,
|
||||
"Ba": 23,
|
||||
"Bb": 42
|
||||
}
|
||||
1
examples/parse__iterator_pair.link
Normal file
1
examples/parse__iterator_pair.link
Normal file
@@ -0,0 +1 @@
|
||||
<a target="_blank" href="https://wandbox.org/permlink/hUJYo1HWmfTBLMGn"><b>online</b></a>
|
||||
1
examples/parse__pointers.link
Normal file
1
examples/parse__pointers.link
Normal file
@@ -0,0 +1 @@
|
||||
<a target="_blank" href="https://wandbox.org/permlink/AWbpa8e1xRV3y4MM"><b>online</b></a>
|
||||
Reference in New Issue
Block a user