Skip to content

Classes without default constructor #385

Answered by stephenberry
Haatschii asked this question in Q&A
Discussion options

You must be logged in to vote

@Haatschii
So, I've been thinking more about this problem. And, I'm torn about adding the feature.

Let's say we have:

struct MyNonDefaultConstructibleClass
{
   MyNonDefaultConstructibleClass(int x, double y) : x(x), y(y) {
      z = x + y;
   }
   
   int x;
   double y;
   double z;
};

template <>
struct glz::meta<MyNonDefaultConstructibleClass>
{
   using T = MyNonDefaultConstructibleClass;
   static constexpr auto value = object("x", &T::x, "y", &T::y);
};

I can make a constructor based on x and y from this object definition. But, there's a good chance I want to serialize z. So, I need another definition to separate the constructor from the serialization and deserialization.

template <…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@Haatschii
Comment options

@stephenberry
Comment options

@Haatschii
Comment options

@stephenberry
Comment options

Answer selected by stephenberry
@Haatschii
Comment options

@stephenberry
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants