Accessing a typedef type that was defined within a template class

A

Alex Snast

Hello guys,

I can't seem to be able to get accsess to a type i declared within a
template class i.e.

template <typename T>
class Array {
public:
typedef std::size_t size_type;

....
....
size_type size() const;

....
private:
....
};

Now i want to implement the size method outside on the class so:
template <typename T>
size_type Array<T>::size() const { ... }

now i know that i can't just use "size_type" but using something like
Array<T>::size_type or Array::size_type can't seem to work either,
however writing T works just fine.

My question is how can i use my typedef size_type outside of the class
declaration?

Any help would be much appreciated, Alex
 
A

acehreli

template <typename T>
class Array {
public:
     typedef std::size_t        size_type;

...
...
    size_type size() const;
[...]

Now i want to implement the size method outside on the class so:
template <typename T>
size_type Array<T>::size() const      { ... }

'typename' before the return type:

template <typename T>
typename Array<T>::size_type Array<T>::size() const
{
return 0;
}

Ali
 
A

Alex Snast

template <typename T>
class Array {
public:
     typedef std::size_t        size_type;
...
...
    size_type size() const;
[...]

Now i want to implement the size method outside on the class so:
template <typename T>
size_type Array<T>::size() const      { ... }

'typename' before the return type:

template <typename T>
typename Array<T>::size_type Array<T>::size() const
{
    return 0;

}

Ali

Thanks Ali, works now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top