typedef'd return type for a template class member function

Discussion in 'C++' started by david.corby@gmail.com, Nov 18, 2004.

  1. Guest

    Hi again everyone!

    I was wondering if there is any way to specify a return type for a
    template class member function that is typedef'd in the class. I.E...

    template <class T> class A {

    public:

    typedef int TD;

    private:

    TD b ();

    };

    template <class T> A<T>::TD b () {

    // Do stuff.

    }

    I know this won't compile, but hopefully you can see what I'm trying to
    do. The type TD will only be used in-class. I know I can stick the
    typedef outside of the class, but I'd like to not pollute that
    namespace.

    Is there any way to make this work? I'm fairly certain I've done it on
    non-templated classes.

    Thanks!
    Dave Corby
    , Nov 18, 2004
    #1
    1. Advertising

  2. wrote:
    > I was wondering if there is any way to specify a return type for a
    > template class member function that is typedef'd in the class. I.E...
    >
    > template <class T> class A {
    >
    > public:
    >
    > typedef int TD;
    >
    > private:
    >
    > TD b ();
    >
    > };
    >
    > template <class T> A<T>::TD b () {


    template<class T> A<T>::TD A<T>::b() {

    >
    > // Do stuff.
    >
    > }
    >
    > I know this won't compile, but hopefully you can see what I'm trying to
    > do. The type TD will only be used in-class. I know I can stick the
    > typedef outside of the class, but I'd like to not pollute that
    > namespace.
    >
    > Is there any way to make this work? I'm fairly certain I've done it on
    > non-templated classes.


    'b'a is a member, you need to qualify the name.

    V
    Victor Bazarov, Nov 18, 2004
    #2
    1. Advertising

  3. Guest

    Oops... yes, of course, my definition was:

    template <class T> A<T>::TD A<T>::b () {

    // Do stuff.
    }

    My mistake, but I didn't make it in the case I'm asking about.
    , Nov 18, 2004
    #3
  4. wrote:
    > Oops... yes, of course, my definition was:
    >
    > template <class T> A<T>::TD A<T>::b () {
    >
    > // Do stuff.
    > }
    >
    > My mistake, but I didn't make it in the case I'm asking about.
    >


    Now, it's a good time to correct your mistake and post the real code
    that doesn't work.

    V
    Victor Bazarov, Nov 19, 2004
    #4
    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. Robert A. T. Kaldy

    template typedef as return type

    Robert A. T. Kaldy, Jul 9, 2003, in forum: C++
    Replies:
    1
    Views:
    413
    Michael Kochetkov
    Jul 9, 2003
  2. Pete Becker
    Replies:
    5
    Views:
    1,012
    =?iso-8859-1?Q?Ali_=C7ehreli?=
    Nov 19, 2004
  3. Replies:
    2
    Views:
    429
    Aleksey Loginov
    Nov 7, 2005
  4. oor
    Replies:
    0
    Views:
    1,341
  5. Replies:
    1
    Views:
    602
Loading...

Share This Page