json icon indicating copy to clipboard operation
json copied to clipboard

Compiler error when using macro NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE

Open ramitrathore opened this issue 1 year ago • 1 comments

Description

struct Contain { Contain() = delete; //Enable the default constructor to make it work explicit Contain(std::string contain) : m_Contain(std::move(contain)){} std::string m_Contain; };

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Contain, m_Contain);

struct Container { std::string m_Name; std::vector<Contain> m_Collection; };

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Container, m_Name, m_Collection); //Compiler error

Reproduction steps

Compiler error - can be easily reproduce since I have added snippet code

Expected vs. actual results

Compiler error

Minimal code example

struct Contain
{
	Contain() = delete; //Enable the default constructor to make it work
  explicit Contain(std::string contain) : m_Contain(std::move(contain)){}
	std::string m_Contain;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Contain, m_Contain);

struct Container
{
	std::string m_Name;
	std::vector<Contain> m_Collection;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Container, m_Name, m_Collection); //Compiler error

Error messages

Compiler error

Compiler and operating system

Windows 10

Library version

3.11.3

Validation

ramitrathore avatar Sep 18 '24 11:09 ramitrathore

The documentation (https://json.nlohmann.me/api/macros/nlohmann_define_type_intrusive/#notes) states the type must be default constructible to use the macro.

nlohmann avatar Sep 18 '24 12:09 nlohmann