cpp newbie- how to convert values from string to ref (address of) variables

StackOverflow https://stackoverflow.com/questions/19691453

  •  02-07-2022
  •  | 
  •  

문제

In C++

This is the function I am coding now-

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

Now within the above function I have to invoke another function that takes as input the same parameters as above 2, but as address of variables.

The declaration for the second function is given below-

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

How do I use the clsname and objname parameters from first function to invoke the second function above. The second function(within itself) extracts the values of 'key' and 'value' from the parameters and then uses them.

도움이 되었습니까?

해결책

If I understand your question right, you want to know how to pass by reference. Parameters to the second function are already being passed by reference. So the answer to your question would be simply:

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

Of course this toy example doesn't make sense as it is, but you haven't told us why you need the first function.

다른 팁

you just call the function with clsname as the parameter, the compiler will do the job for you

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top