473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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 2290

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;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.