Skip to content

Instantly share code, notes, and snippets.

@padenot
Created November 30, 2010 21:12
Show Gist options
  • Save padenot/722415 to your computer and use it in GitHub Desktop.
Save padenot/722415 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <assert.h>
int main()
{
std::vector<int> vec_int;
vec_int.push_back(1);
// z et vec_int.front() sont exactement la même variable
int& z = vec_int.front();
std::cerr << z << std::endl;
z = 4;
std::cerr << vec_int.front() << std::endl;
// Même valeur
assert(z == vec_int.front());
// Même adresse : pas de copie
assert(&z == &(vec_int.front()));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment