Any way to avoid write "template <class T>" every line?

If function definitions are implemented outside of the class, then "template <class T>" is needed before the function declaration... for example,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
template <class T>
class A {
    T value;
public:
    void routine1();
    void routine2();
    // More routines...
}

template <class T>
void A<T>::routine1() { // ... }

template <class T>
void A<T>::routine1() { // ... }

// and so on for all routines... 

My question is, is there any way to avoid write "template <class T>" every time there is a function definition of class A?
Last edited on
No.
[devil's advocate]

Just use a macro:

1
2
3
4
5
#define TTV template <class T> void A<T>::

TTV routine1() { ... }

TTV routine2() { ... }


[/devil's advocate]

BTW, don't do that. When you use macros, they should have names that cannot conflict, and the example can conflict with other people's junk. For all the typing you are not saving, it is better to cut and paste some template headers a few times...
Last edited on
Topic archived. No new replies allowed.