CPP新手 - 如何将值从字符串转换为引用(地址)变量



In C++

这是我现在正在编码的功能-

   insertobjectnames(std::string clsname, std::string objname)

现在在上面的函数中,我必须调用另一个函数,该函数将与上述 2 相同的参数作为输入,但作为变量的地址。

第二个函数的声明如下-

   int BitmapHashMap::Insertnew(const std::string& key, std::string& value)

如何使用第一个函数中的 clsname 和 objname 参数来调用上面的第二个函数。第二个函数(在自身内部)从参数中提取"键"和"值"的值,然后使用它们。

如果我理解你的问题正确,你想知道如何通过引用。第二个函数的参数已通过引用传递。因此,您的问题的答案很简单:

void insertobjectnames(std::string clsname, std::string objname) {
    BitmapHashMap hashmap;
    hashmap.Insertnew(clsname, objname);
}

当然,这个玩具示例本身没有意义,但您还没有告诉我们为什么需要第一个功能。

您只需使用 clsname 作为参数调用函数,编译器将为您完成这项工作

最新更新