Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ template class syntax

In my class, we are studying C++98 so I'm trying to find the proper syntax.

How should one write the declaration:

template <class T>
class A{
public:
    A();
    A(const A &rhs);
    A &operator=(const A &rhs);
};

Or should it be like this:

template <class T>
class A{
public:
    A();
    A(const A<T> &rhs);
    A &operator=(const A<T> &rhs);
};

I guess the implementation is the same for both of them.

Are they different from one to another?

like image 401
Dannz Avatar asked Dec 23 '22 20:12

Dannz


1 Answers

Given

template <class T> class A { ... };

The names A<T> and A are both valid names to refer to A<T> in the scope of the class. Most prefer to use the simpler form, A, but you may use A<T>.

like image 69
R Sahu Avatar answered Dec 26 '22 10:12

R Sahu