mercredi 3 avril 2019

Why c++ does has not provided the ability to bundle multiple functions / class definitions under the same template declaration?

I was writing code for a templated class and realised that for every function, we have to write template declaration for each member function while defining it. Eg.

template <typename T>
class A {
  public:
    T func1();
    T func2();
};

template<typename T>
T A<T>::func1() {/* code */}
template<typename T>
T A<T>::func2() {/* code */}

Is there any specific reason that c++ does not provide functionality to write this with a syntax something like below :

template <typename T> { // start of Templated block
class A {
  public:
    T func1();
    T func2();
};

T A<T>::func1() {/* code */}
T A<T>::func2() {/* code */}
} // one template declaration for multiple definitions.

Aucun commentaire:

Enregistrer un commentaire