473,671 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ 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 2314

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
3210
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 writing one object in C# which will take the entire table tag contents and renders. Ie., we need to pass "<table>………… <thead>……</thead>. <tr>.<td> <td>..<tr>.<td> <td> </table>" content to
14
1827
by: SoilMan | last post by:
Consider the following: class xyz { public: template <typename T> void foo(T x) { cout << "foo<T> " << x << endl; }
4
5073
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() { return 0;
3
2356
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
2816
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 return (Base*->type_fild >= Derived_typeid)? Base*: 0;
3
1364
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
3533
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
3608
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 class simple_vector<that is a hand-rolled substitute for array<>. With the latter I have code that tracks all allocations and destructions, so I can account for all the memory. The question is about std::vector<-- how can I track memory usage
6
5425
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
8481
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8400
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8602
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7441
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6234
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4412
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.