Quote Originally Posted by Daved
>> This is pass by value
Nope, both are passing the string by reference. The output of both is "Goodbye world!". If you were passing the string by value, then the output would be "Hello world!".
Yes you're right. Sorry.
Code:
#include <iostream>
#include <string>
using namespace std;


void SomeFunction(string** pointerToStringPointer)
{
    cout << "pointerToStringPointer      = 0x" << hex << reinterpret_cast<unsigned int>(pointerToStringPointer) << endl;

    **pointerToStringPointer = "Goodbye world!";
}


int main()
{
    string   helloString                 = "Hello world!";
    string*  pointerToHelloString        = &helloString;
    string** pointerToHelloStringPointer = &pointerToHelloString;

    cout << "helloString                 = 0x" << hex << reinterpret_cast<unsigned int>(&helloString) << endl;
    cout << "pointerToHelloString        = 0x" << hex << reinterpret_cast<unsigned int>(pointerToHelloString) << endl;
    cout << "pointerToHelloStringPointer = 0x" << hex << reinterpret_cast<unsigned int>(pointerToHelloStringPointer) << endl;

    SomeFunction(pointerToHelloStringPointer);
    
    cout << helloString;
};
Passing by value is like this:
Code:
#include <iostream>
#include <string>
using namespace std;


void SomeFunction(string theString)
{
    theString = "Goodbye World!";
}


int main()
{
    string   helloString                 = "Hello world!";
    string*  pointerToHelloString        = &helloString;
    string** pointerToHelloStringPointer = &pointerToHelloString;

    SomeFunction(**pointerToHelloStringPointer);
    
    cout << helloString;
};