Created
August 26, 2018 09:56
-
-
Save kobake/127a57a1c686d13748ef6f7e48c4c248 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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