Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mryoshio/8df1158814802cafb9e7 to your computer and use it in GitHub Desktop.
Save mryoshio/8df1158814802cafb9e7 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <vector>
/*
Usage: g++ -std=c++11 foo.cpp
*/
using namespace std;
struct Entry {
string name;
int number;
};
template<typename T>
class Vec : public std::vector<T> {
public:
using vector<T>::vector;
T& operator[](int i) { return vector<T>::at(i); }
};
int main() {
Vec<Entry> v = {
{"Taro", 1111},
{"Hanako", 2222},
{"Saburo", 3333}
};
v[4] = {"Shirou", 444};
// v.at(4) = {"Shirou", 444};
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment