Created
March 19, 2019 04:38
-
-
Save MatthewThePham/2f0a64c5f56d611e9b7787c598373ead to your computer and use it in GitHub Desktop.
cpp function dereferencing example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//basic passing by reference example using vectors (using &) | |
//more info | |
//https://www.geeksforgeeks.org/passing-by-pointer-vs-passing-by-reference-in-c/ | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
void temp( vector<string> * temp); | |
int main() | |
{ | |
vector<string> idVector; | |
temp(&idVector); | |
cout<<idVector[0] << endl; | |
cout<<idVector[1]; | |
return 0; | |
} | |
void temp( vector<string> * temp){ | |
temp->push_back("hello"); //normally without pointers, temp.push_back("hello"), but arrow will dereference and accessing the member | |
temp->push_back("bigboi"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment