Skip to content

Passing an iteration object by reference to a function #967

@ghost

Description

Bug Report

  • What is the issue you have?
    I cannot pass a JSON iteration object by reference to a function

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

nlohmann::json j;
std::ifstream if( "C:\\example.json" );
j << if;
if.close( );

/*...*/

void square( int *in )
{
    in *= in;
}

/*...*/

square( &j[ "int" ] );
  • What is the expected behavior?
    To be able to pass the object by reference, rather than this:
int buf = j[ "int" ];
square( &buf );
j[ "int" ] = buf;
  • And what is the actual behavior instead?
    Error (active) E0167 argument of type "nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, uint64_t, double, std::allocator, nlohmann::adl_serializer> *" is incompatible with parameter of type "int *"

  • Which compiler and operating system are you using? Is it a supported compiler?
    Visual Studio 2017 15.5.3, Windows 10

  • Did you use a released version of the library or the version from the develop branch?
    Released

  • If you experience a compilation error: can you compile and run the unit tests?
    Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions