T
Tony Johansson
Hello Experts!
I have the following Array template class see below.
I execute these three statements
statement 1: Array<int> x(5);
statement 2: cin >>x[1];
statement 3: Array<int>::element_type y = x[1];
but I can't understand the last one which is
Array<int>::element_type y = x[1];
We have a typedef T element_type; in the template Array class see below
and in my example I use int as the type parameter for T so
that would mean that it says
Array<int>::int y = x[1];
this is even more confusing for me.
If the Array template class for example had a static variable with name
number then you would
use Array<int>::number; to access this static variable.
template <typename T>
class Array
{
public:
Array(size_t=100); // size_t is predefined
Array(const Array<T>&);
Array<T>& operator=(const Array<T>&);
virtual ~Array();
virtual const T& operator[](int) const;
virtual T& operator[](int);
int size() const;
typedef T element_type;
protected:
size_t size_;
T* array;
};
Many thanks
//Tony
I have the following Array template class see below.
I execute these three statements
statement 1: Array<int> x(5);
statement 2: cin >>x[1];
statement 3: Array<int>::element_type y = x[1];
but I can't understand the last one which is
Array<int>::element_type y = x[1];
We have a typedef T element_type; in the template Array class see below
and in my example I use int as the type parameter for T so
that would mean that it says
Array<int>::int y = x[1];
this is even more confusing for me.
If the Array template class for example had a static variable with name
number then you would
use Array<int>::number; to access this static variable.
template <typename T>
class Array
{
public:
Array(size_t=100); // size_t is predefined
Array(const Array<T>&);
Array<T>& operator=(const Array<T>&);
virtual ~Array();
virtual const T& operator[](int) const;
virtual T& operator[](int);
int size() const;
typedef T element_type;
protected:
size_t size_;
T* array;
};
Many thanks
//Tony