Accessing a typedef type that was defined within a template class

Discussion in 'C++' started by Alex Snast, Aug 30, 2008.

  1. Alex Snast

    Alex Snast Guest

    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
    Alex Snast, Aug 30, 2008
    #1
    1. Advertising

  2. Alex Snast

    Guest

    On Aug 30, 12:37 pm, Alex Snast <> wrote:

    > 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
    , Aug 30, 2008
    #2
    1. Advertising

  3. Alex Snast

    Alex Snast Guest

    On Aug 30, 10:32 pm, wrote:
    > On Aug 30, 12:37 pm, Alex Snast <> wrote:
    >
    > > 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.
    Alex Snast, Aug 30, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Ying
    Replies:
    2
    Views:
    588
    James Ying
    Oct 28, 2003
  2. Replies:
    3
    Views:
    466
    Victor Bazarov
    Nov 19, 2004
  3. Oodini
    Replies:
    1
    Views:
    1,767
    Keith Thompson
    Sep 27, 2005
  4. oor
    Replies:
    0
    Views:
    1,346
  5. Replies:
    1
    Views:
    604
Loading...

Share This Page