473,467 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2294

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are...
14
by: SoilMan | last post by:
Consider the following: class xyz { public: template <typename T> void foo(T x) { cout << "foo<T> " << x << endl; }
4
by: Gary li | last post by:
Hi, all I find "template template" class cann't been compiled in VC6 but can ok in Redhat9. I write a test program like as: template< template<class> class T> class A { }; int main() {...
3
by: Nate Barney | last post by:
I have: // base class for Vector and Matrix template <unsigned N,typename Value=float> class NonScalar { public: Value *ptr() { return e; } const Value *ptr() const { return e; }
15
by: Grizlyk | last post by:
Hello. Returning to question of manual class type identification, tell me, for ordinary inheritance is C++ garantee that dynamic_cast<Derived*>(Base*) can be implemented similarly to ...
3
by: George2 | last post by:
Hello everyone, I sometimes saw code with template<and followed by a class definition, like, template<class { // class definition
10
by: jason.cipriani | last post by:
Is there any difference between declaring a template parameter as a "typename" or a "class"? E.g. template <class TT f() { } template <typename TT g() { } Thanks, Jason
8
by: jacek.dziedzic | last post by:
Hi! I need to be able to track memory usage in a medium-sized application I'm developing. The only significant (memory-wise) non- local objects are of two types -- std::vector<and of a custom...
6
by: Juha Nieminen | last post by:
joseph cook wrote: Not always. By default, yes, but you can specify other comparators, eg: std::map<int, int, std::greaterreversedMap;
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.