Converting from std::vector<> to a double pointer?
c++, casting, pointers, stdvector
Solution
You already know that `&myCharVector[0]` is a pointer to `char`. So if you store it in a variable:
char *cstr = &myCharVector[0];
then you can take the address of that variable:
char **ptrToCstr = &cstr;
But simply dereferencing twice like this:
char **ptrToCstr = &(&myCharVector[0])
is invalid because the value `(&myCharVector[0])` isn't stored in memory anywhere yet.
Problem
I was wondering out of curiosity if it is possible to cast a std::vector<> to a double pointer. I've never had an issue passing a std::vector as a pointer in this fashion: ``` std::vector<char> myCharVector; myCharVector.push_back('a'); myCharVector.push_back('b'); myCharVector.push_back('c'); char *myCharPointer = &myCharVector[0]; ``` So I was curious if it was possible to assign the address of the pointer in a similar way to this: ``` char *myPointer = "abc"; char **myDoublePointer = &myPointer; ``` I've tried: ``` char **myDoublePointer = (char**)&myCharVector; ``` But it doesn't work. Is there any way of achieving this?