0

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.

  • 1
    You may have confused the usage of the & operator. You say that the insertnew function expects the address of the parameters but its declaration expects a reference to the parameters. – linuxfever Oct 30 '13 at 19:03
  • They're const-references. Pass your by-value params on, or if you're not modifying them in *your* function, make *your* params const-references as well. (i.e. make your params match their signature if you don't modify `clsname` and `objname` in your function). – WhozCraig Oct 30 '13 at 19:12

2 Answers2

2

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.

A.B.
  • 15,364
  • 3
  • 61
  • 64
  • if Insertnew has 'value'as a string pointer variable, and i wish to pass a string variable as a parameter to it, then how would I do it? Its just that I am conceptually confused about passing a string as a param where a pointer to string is a function parameter(in above question the function parameter was call by reference). Thanks in advance, Arvind. – user2880330 Oct 31 '13 at 00:15
0

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

user1708860
  • 1,683
  • 13
  • 32