I have little C++ experience. My question is more about confirming if I'm thinking correctly with some queries. I was trying to understand a code and it has the following line:
string ltrim(const string &);
I saw the following answers: 1. What is the difference between "std::string const &s" and "const std::string &s"? 2. https://www.geeksforgeeks.org/stdstring-class-in-c/ 3. https://codereview.stackexchange.com/questions/32842/passing-parameters-by-reference
I know the concept of call by value and call by reference.
- What is 'ltrim'?
It seems to me that it is a function name declared here because I know C++ doesn't have a predefined function with this name. Am i correct to assume that it means that it is a function named 'ltrim' of type 'string' and this function has a parameter 'a constant string type'.
However, usually we have functions like:
void abc (int &a)
where a is a variable. What is the variable in:
string ltrim(const string &);
because 'const' has a predefined meaning and 'string' is a datatype. What is the variable passed in the parameter?
- Also, if there is no variable, what does '&' do here. I understand call by reference some what w.r.t C++, but I don't see a variable name, I don't know what s being used to pass.
I tried looking on internet for some information but i couldn't narro down to a place which explains this in terms of string.
Aucun commentaire:
Enregistrer un commentaire