Skip to content

Instantly share code, notes, and snippets.

@kobake
Created August 26, 2018 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobake/127a57a1c686d13748ef6f7e48c4c248 to your computer and use it in GitHub Desktop.
Save kobake/127a57a1c686d13748ef6f7e48c4c248 to your computer and use it in GitHub Desktop.
#include <stdio.h>
// As generics
template <class T>
class List {
public:
List() {
m_count = 0;
}
void Add(const T& t) {
m_buf[m_count++] = t;
}
int Count() const {
return m_count;
}
T& operator[](int index) {
return m_buf[index];
}
private:
int m_count;
T m_buf[256];
};
int main()
{
List<int> a;
a.Add(10);
a.Add(20);
printf("%d\n", a[0]);
printf("%d\n", a.Count());
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment