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
Re: How to serialize a new data type [message #52580 is a reply to message #52578] Wed, 23 October 2019 13:46 Go to previous messageGo to previous message
Oblivion is currently offline  Oblivion
Messages: 1094
Registered: August 2007
Senior Contributor
Hello Koldo,

On Linux with GCC I get the same error. The problem seems to be namespace.
Try this one: Smile

#include <Core/Core.h>


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

using namespace Upp;

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");
}


This works on GCC and CLANG (on Linux).

Best regards,
Oblivion


[Updated on: Wed, 23 October 2019 13:49]

Report message to a moderator

 
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: Wed May 15 10:01:55 CEST 2024

Total time taken to generate the page: 0.02826 seconds