I've always passed by reference by dereferencing in the function prototype and then referencing the variable when passing in the parameter. I've recently seen what seems to be a way to pass by reference as well but it works slightly different. It references the parameter in the prototype but does not expect any sort of (de)reference when inputting the value into the function. When using my method, you must use the "->" operator to access member functions, but when using the other method you can use the "." operator. Can you please explain the difference between these two methods and if there is a more commonly used method in practice. I have some example code below to better explain what I mean:
#include <iostream>
#include <string>
using namespace std;
void something(string *byRef, string &dontKnow);
int main(int argc, const char * argv[])
{
string test1 = "test string 1";
string test2 = "second test";
something(&test1, test2);
return 0;
}
void something(string *byRef, string &dontKnow) {
cout << "test1 address = " << byRef << "\nsize = " << byRef->size() << endl;//size function accessed by "->"
cout << "test2 address = " << &dontKnow << "\nsize = " << dontKnow.size() << endl;//now accessed by "." and reference operator required for address
}