0

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 first one as string and second one as string pointer variable

The declaration for the second function is given below-

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

How do I use the objname parameter from the first function to invoke the second function above? The second function (within itself) extracts the value of key2 from the parameters and then uses them as per requirements.

1
  • First, there's usually no good reason for analyse to expect a pointer for key2. It should take a reference (or a const reference, if it's not going to modify key2). Similarly, using const reference parameters instead of passing strings by value is preferable. Commented Oct 31, 2013 at 21:40

1 Answer 1

1

The & operator in C++: its the address-of operator: basically a variable to pointer converter! Ex:

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
Sign up to request clarification or add additional context in comments.

1 Comment

@awesomeyi- AFAIK SO asks for answers- hence please post the answer otherwise I cannot accept your hint as the answer.(And I have understood what you mean- thanks a lot :) )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.