Skip to content

Instantly share code, notes, and snippets.

@jcsalterego
Created May 12, 2009 05:07
Show Gist options
  • Select an option

  • Save jcsalterego/110319 to your computer and use it in GitHub Desktop.

Select an option

Save jcsalterego/110319 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
// prototype
vector<int> & buy();
int main ()
{
vector<int> j;
j = buy();
for (int i = 0; i < j.size(); i++) {
cout << "j[" << i << "] = " << j[i] << endl;
}
// should print out:
// j[0] = 1
// j[1] = 2
// j[2] = 3
return 0;
}
vector<int> & buy()
{
vector<int> *foobar = new vector<int>;
foobar->push_back(1);
foobar->push_back(2);
foobar->push_back(3);
return *foobar;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment