template<> keyword - unexpected hides base typedefs

Discussion in 'C++' started by Grizlyk, Jan 15, 2007.

  1. Grizlyk

    Grizlyk Guest

    Hello.

    Why were base class "typedefs" hidden by template<> and explicit usage
    of them does not work too?

    Try open only one of the lines in the example below
    //using Tparent::Tptr;
    //typedef Tparent::Tptr Tptr;

    Consider example:

    template< class A, class B> class Z;
    template< class A, class B> class Ext1;


    template< class A, class B>
    class Base
    {
    public:
    typedef Z<A,B> Tptr;
    };


    template< class A >
    class Derived: public Base<A, Ext1<int,int> >
    {
    public:
    typedef Base<A, Ext1<int,int> > Tparent;

    using Tparent::Tptr;
    typedef Tparent::Tptr Tptr;

    inline void test(const Tptr obj)throw();
    };


    class Base2
    {
    public:
    typedef Z<int,int> Tptr;
    };


    class Derived2: public Base2
    {
    public:
    typedef Base2 Tparent;

    using Tparent::Tptr;
    //typedef Tparent::Tptr Tptr;

    inline void test(const Tptr obj)throw();
    };


    /*

    5.cpp:18: error: ISO C++ forbids declaration of 'Tptr' with no type
    5.cpp:18: error: cannot declare member 'Base<A, Ext1<int, int> >::Tptr'

    within 'Derived<A>'
    5.cpp:18: error: expected ';' before 'Tptr'
    5.cpp:20: error: expected ',' or '...' before 'obj'
    5.cpp:20: error: ISO C++ forbids declaration of 'Tptr' with no type

    */
     
    Grizlyk, Jan 15, 2007
    #1
    1. Advertisements

  2. Grizlyk

    Ondra Holub Guest

    Grizlyk napsal:
    > Hello.
    >
    > Why were base class "typedefs" hidden by template<> and explicit usage
    > of them does not work too?
    >
    > Try open only one of the lines in the example below
    > //using Tparent::Tptr;
    > //typedef Tparent::Tptr Tptr;
    >
    > Consider example:
    >
    > template< class A, class B> class Z;
    > template< class A, class B> class Ext1;
    >
    >
    > template< class A, class B>
    > class Base
    > {
    > public:
    > typedef Z<A,B> Tptr;
    > };
    >
    >
    > template< class A >
    > class Derived: public Base<A, Ext1<int,int> >
    > {
    > public:
    > typedef Base<A, Ext1<int,int> > Tparent;
    >
    > using Tparent::Tptr;
    > typedef Tparent::Tptr Tptr;
    >
    > inline void test(const Tptr obj)throw();
    > };
    >
    >
    > class Base2
    > {
    > public:
    > typedef Z<int,int> Tptr;
    > };
    >
    >
    > class Derived2: public Base2
    > {
    > public:
    > typedef Base2 Tparent;
    >
    > using Tparent::Tptr;
    > //typedef Tparent::Tptr Tptr;
    >
    > inline void test(const Tptr obj)throw();
    > };
    >
    >
    > /*
    >
    > 5.cpp:18: error: ISO C++ forbids declaration of 'Tptr' with no type
    > 5.cpp:18: error: cannot declare member 'Base<A, Ext1<int, int> >::Tptr'
    >
    > within 'Derived<A>'
    > 5.cpp:18: error: expected ';' before 'Tptr'
    > 5.cpp:20: error: expected ',' or '...' before 'obj'
    > 5.cpp:20: error: ISO C++ forbids declaration of 'Tptr' with no type
    >
    > */


    There is missing keyword typedef:

    template< class A, class B> class Z;
    template< class A, class B> class Ext1;

    template< class A, class B>
    class Base
    {
    public:
    typedef Z<A,B> Tptr;

    };

    template< class A >
    class Derived: public Base<A, Ext1<int,int> >
    {
    public:
    typedef Base<A, Ext1<int,int> > Tparent;

    using Tparent::Tptr;
    typedef typename Tparent::Tptr Tptr2;

    inline void test(const Tptr2 obj)throw();

    };

    class Base2
    {
    public:
    typedef Z<int,int> Tptr;

    };

    class Derived2: public Base2
    {
    public:
    typedef Base2 Tparent;

    using Tparent::Tptr;
    //typedef Tparent::Tptr Tptr;

    inline void test(const Tptr obj)throw();

    };

    int main()
    {
    }
     
    Ondra Holub, Jan 15, 2007
    #2
    1. Advertisements

  3. Grizlyk

    Grizlyk Guest

    Ondra Holub wrote:

    > There is missing keyword typedef:


    Where exactly?

    I want to say, that compiler can not compile even well defined (known)
    type from base class.
     
    Grizlyk, Jan 15, 2007
    #3
  4. Grizlyk

    Ondra Holub Guest

    Grizlyk napsal:
    > Ondra Holub wrote:
    >
    > > There is missing keyword typedef:

    >
    > Where exactly?
    >
    > I want to say, that compiler can not compile even well defined (known)
    > type from base class.


    Oh, sorry. I made typo - there is missing typename (not typedef) in
    typedef typename Tparent::Tptr Tptr2

    Here is a touched part of code:

    template< class A >
    class Derived: public Base<A, Ext1<int,int> >
    {
    public:
    typedef Base<A, Ext1<int,int> > Tparent;

    using Tparent::Tptr;
    typedef typename Tparent::Tptr Tptr2;

    inline void test(const Tptr2 obj)throw();
    };
     
    Ondra Holub, Jan 15, 2007
    #4
  5. Grizlyk

    Grizlyk Guest

    Ondra Holub write:

    > Oh, sorry. I made typo - there is missing typename (not typedef) in
    > typedef typename Tparent::Tptr Tptr2
    >
    > Here is a touched part of code:
    >
    > template< class A >
    > class Derived: public Base<A, Ext1<int,int> >
    > {
    > public:
    > typedef Base<A, Ext1<int,int> > Tparent;
    >
    > using Tparent::Tptr;
    > typedef typename Tparent::Tptr Tptr2;
    >
    > inline void test(const Tptr2 obj)throw();
    > };


    Yes, it is work. Thanks.
    But it is very not clear to me, why I can declare with "using" method
    of base class, but can not do type.
     
    Grizlyk, Jan 15, 2007
    #5
    1. Advertisements

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. emerth
    Replies:
    3
    Views:
    411
    emerth
    Aug 8, 2003
  2. Tom Richardson
    Replies:
    1
    Views:
    372
    Victor Bazarov
    Dec 19, 2003
  3. eiji
    Replies:
    5
    Views:
    525
    Rolf Magnus
    Dec 6, 2005
  4. nguillot
    Replies:
    5
    Views:
    609
  5. Hicham Mouline
    Replies:
    1
    Views:
    696
    Victor Bazarov
    Apr 20, 2009
Loading...

Share This Page