FANDOM


Templates are a feature implemented in some languages that allow you to write functions and classes that can accept any type of parameter, when they would otherwise only accept one type of parameter.

C++ Edit

In C++, template functions are declared like so:

template<class T>
T add(T x, T y)
{
    T tmp = (x + y);
    return tmp;
}

and are implemented like:

add<int>(5, 5)

Template classes:

template <class T>
class test
{
private:
  T asdf;
};

test<int> instance;

Static member variables:

template <class T>
class test
{
private:
  static T stv;
};

template <class T> T test<T>::stv;
template <> int test<int>::stv = 4;


16px-Pencil

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.