Skip to content

Instantly share code, notes, and snippets.

@HybridEidolon
Created October 20, 2012 06:54
Show Gist options
  • Save HybridEidolon/3922427 to your computer and use it in GitHub Desktop.
Save HybridEidolon/3922427 to your computer and use it in GitHub Desktop.
returning reference vector
#include <iostream>
#include <vector>
using namespace std;
void ints(vector<int>& tofill) {
tofill.push_back(1);
tofill.push_back(2);
tofill.push_back(3);
}
int main(int argc, char** argv) {
vector<int> stuff(); // or vector<int> stuff = vector<int>();
int i;
ints(stuff);
for (i = 0; i < stuff.size(); i++) {
cout << stuff[i] << endl;
}
}
// prints
// 1
// 2
// 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment