Skip to content

How to provide function json& to_json() which is similar as 'void to_json(json&j, const CObject& obj)' ? #1650

@akeyliu

Description

@akeyliu
  • Describe what you want to achieve.
    I've deifned functions to_json for user defined classes, i.e.
    class foo
    {
    friend inline void to_json(json& j, const foo& obj) {...}.
    }
    These code work well.
    But I wonder if we can define the function like 'json& to_json(void) {...}' as a memeber function in the class foo?
    The purpose for this function is that I want to use virtual function of basic class, and all derived classes can automatic define their reload funtion such as 'cout << to_json() << endl';
    If can, how to define this function?

  • Describe what you tried.

  • Describe which system (OS, compiler) you are using.
    Ubuntu 18.04 LTS, g++ 7.3;

  • Describe which version of the library you are using (release version, develop branch).
    the master version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions