Skip to content

Instantly share code, notes, and snippets.

@Zetaeta
Last active December 17, 2015 17:29
Show Gist options
  • Save Zetaeta/5646731 to your computer and use it in GitHub Desktop.
Save Zetaeta/5646731 to your computer and use it in GitHub Desktop.
Template class example
template <class T>
class Array5 {
public:
T data[5];
};
int main() {
Array5<int> intarr;
intarr.data[0] = 3;
Array5<string> strarr;
strarr.data[2] = "meow";
}
//When the compiler compiles it, it sees that you use the class Array5<int> and Array5<string>. It generates these classes by replacing every instance of "T" in Array5 with "int" or "string", and the result would look like:
class Array5<int> {
public:
int data[5];
};
class Array5<string> {
public:
string data[5];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment