Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » How to serialize a new data type
How to serialize a new data type [message #52578] Wed, 23 October 2019 10:58 Go to previous message
koldo is currently offline  koldo
Messages: 3358
Registered: August 2008
Senior Veteran
I am lost. This sample to serialize a std::complex compiles in MSVC but gets this error with MinGW:
error: 'struct std::complex<double>' has no member named 'Jsonize'

#include <Core/Core.h>

using namespace Upp;

template <class T>
void Jsonize(JsonIO& io, std::complex<T>& var) {
	T re, im;
	if (io.IsStoring()) {
		re = var.real();	
		im = var.imag();
	}
	io("re", re)("im", im);
	if (io.IsLoading()) {
		var.real(re);
		var.imag(im);
	}
}

struct Demo {
	std::complex<double> val;
	void Jsonize(JsonIO& io) 	{io("val", val);}
};

CONSOLE_APP_MAIN
{
	Demo demo;
	demo.val =  std::complex<double>(1, 2);
	StoreAsJsonFile(demo, "filename.json");
}


Best regards
IƱaki
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: [SOLVED] Vector Bug
Next Topic: Long time running program and Vector
Goto Forum:
  


Current Time: Mon Apr 29 11:31:57 CEST 2024

Total time taken to generate the page: 0.02927 seconds