C++ 如何在使用字符串指针变量作为输入参数的函数中使用字符串值作为参数

C++ 如何在使用字符串指针变量作为输入参数的函数中使用字符串值作为参数,c++,string,pointers,C++,String,Pointers,这就是我现在正在编写的函数- insertobjectnames(std::string clsname, std::string objname) 现在,在上面的函数中,我必须调用另一个函数,该函数使用与上面2相同的参数作为输入,但第一个作为字符串,第二个作为字符串指针变量 下面给出了第二个函数的声明- int analyse(const std::string key, std::string * key2) 如何使用第一个函数中的objname参数调用上面的第二个函数?第二个函数(

这就是我现在正在编写的函数-

insertobjectnames(std::string clsname, std::string objname)
现在,在上面的函数中,我必须调用另一个函数,该函数使用与上面2相同的参数作为输入,但第一个作为字符串,第二个作为字符串指针变量

下面给出了第二个函数的声明-

 int  analyse(const std::string key, std::string * key2)

如何使用第一个函数中的
objname
参数调用上面的第二个函数?第二个函数(内部)从参数中提取
key2
的值,然后根据需要使用它们。

C++中的
&
运算符:它是运算符的地址:基本上是一个变量到指针的转换器!例:

int a = 0;
int *pointertoa = &a;
//So
std::string s;
std::string *ps = &s; //Extracting the "key" ps is a pointer to s
analyse(key, &objname); //should be the right way to pass the parameter as a pointer

@awesomeyi-AFAIK要求答案-因此请发布答案,否则我无法接受你的提示作为答案。(我理解你的意思-非常感谢:))好的,我先发布了答案,通常没有好的理由让
分析
期望
键2有指针。它应该接受一个引用(或者常量引用,如果它不打算修改key2)。类似地,最好使用
const reference
参数而不是按值传递字符串。