Skip to content

Instantly share code, notes, and snippets.

@MatthewThePham
Created March 19, 2019 04:38
Show Gist options
  • Save MatthewThePham/2f0a64c5f56d611e9b7787c598373ead to your computer and use it in GitHub Desktop.
Save MatthewThePham/2f0a64c5f56d611e9b7787c598373ead to your computer and use it in GitHub Desktop.
cpp function dereferencing example
//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