按值或引用

时间:2017-07-09 16:20:04

标签: c++ nlohmann-json

我正在使用nlohmann的JSON库来解析JSON文件。在这种情况下,我想知道在传递对象的效率和开销方面,通过值或引用传递JSON对象是否是最佳实践。

这是一个简短的例子,显示我会按值传递它:

#include <iostream>
#include <string>
#include <fstream>
#include "json.hpp"

void read_json(nlohmann::json j) /// pass by value or reference?
{
    ///...
}

int main()
{
    std::string file_name = "asd.json";

    std::ifstream filename_stream(file_name);
    nlohmann::json j = nlohmann::json::parse(filename_stream);

    read_json(j);

    return 0;
}   

0 个答案:

没有答案
相关问题