469,329 Members | 1,470 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,329 developers. It's quick & easy.

template<> keyword - unexpected hides base typedefs

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 Bclass Z;
template< class A, class Bclass Ext1;
template< class A, class B>
class Base
{
public:
typedef Z<A,BTptr;
};
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,intTptr;
};
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

*/

Jan 15 '07 #1
4 2007

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 Bclass Z;
template< class A, class Bclass Ext1;
template< class A, class B>
class Base
{
public:
typedef Z<A,BTptr;
};
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,intTptr;
};
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 Bclass Z;
template< class A, class Bclass Ext1;

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

};

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,intTptr;

};

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

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

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

};

int main()
{
}

Jan 15 '07 #2

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.

Jan 15 '07 #3

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();
};

Jan 15 '07 #4

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.

Jan 15 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by SoilMan | last post: by
3 posts views Thread by Nate Barney | last post: by
15 posts views Thread by Grizlyk | last post: by
3 posts views Thread by George2 | last post: by
10 posts views Thread by jason.cipriani | last post: by
8 posts views Thread by jacek.dziedzic | last post: by
6 posts views Thread by Juha Nieminen | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.