This commit is contained in:
nlohmann
2025-01-17 05:54:35 +00:00
parent 4ce072a05e
commit 9cd1c63d00
330 changed files with 5398 additions and 1012 deletions

View 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;
}

View File

@@ -0,0 +1,6 @@
{
"Aa": 3.142,
"Ab": 1.777,
"Ba": 23,
"Bb": 42
}

View File

@@ -0,0 +1 @@
<a target="_blank" href="https://wandbox.org/permlink/hUJYo1HWmfTBLMGn"><b>online</b></a>

View File

@@ -0,0 +1 @@
<a target="_blank" href="https://wandbox.org/permlink/AWbpa8e1xRV3y4MM"><b>online</b></a>