473,954 Members | 8,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

specialized template class question

I have the ff template class:

template <class T1, class T2class Periodic ;

I have two questions/problems

Q1).

I want to specialize it further into two template classes:

Periodic<Class1 , T2//specialized for class1
Periodic<Class2 , T2//specialized for class2
Q2)
Furthermore, I would like to typedef these new classes, e.g.

typedef Periodic<Class1 , T2MyTemplate1 ;

Is this possible ?
Apr 12 '07 #1
8 1675
2b|!2b==? wrote:
I have the ff template class:

template <class T1, class T2class Periodic ;

I have two questions/problems

Q1).

I want to specialize it further into two template classes:

Periodic<Class1 , T2//specialized for class1
Periodic<Class2 , T2//specialized for class2

Yes.

tempalate<class Tclass Periodic<Class1 , T{ ...
templlate<class Tclass Periodic<Class2 , T{ ...
Q2)
Furthermore, I would like to typedef these new classes, e.g.

typedef Periodic<Class1 , T2MyTemplate1 ;

Is this possible ?
Not yet. Search for "template typedefs" in the archives.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 12 '07 #2


Victor Bazarov wrote:
2b|!2b==? wrote:
>>I have the ff template class:

template <class T1, class T2class Periodic ;

I have two questions/problems

Q1).

I want to specialize it further into two template classes:

Periodic<Clas s1, T2//specialized for class1
Periodic<Clas s2, T2//specialized for class2

Yes.

tempalate<class Tclass Periodic<Class1 , T{ ...
templlate<class Tclass Periodic<Class2 , T{ ...

Done. Thanks
>>Q2)
Furthermore , I would like to typedef these new classes, e.g.

typedef Periodic<Class1 , T2MyTemplate1 ;

Is this possible ?


Not yet. Search for "template typedefs" in the archives.

V
I looked this up, and came up with the ff struct declaration:

//The follwing is in myheader.h

template<class T>
struct MyStruct
{
typedef Periodic<Class1 , T> Type1;
typedef Periodic<Class2 , T> Type2;
};

MyStruct<Class1 >::Type1 MyTypedef1 ;
MyStruct<Class2 >::Type2 MyTypedef2 ;
//Now in my souce file, I have the following:

#include "myheader.h "

......

MyClass
{
public:
MyClass();
MyClass(const MyClass&);
.....
private:
MyTypedef1 m_type_def1 ; // <- compiler barfs here
};
What am I doing wrong ?

Apr 12 '07 #3
Correction:

This :
template<class T>
struct MyStruct
{
typedef Periodic<Class1 , T Type1;
typedef Periodic<Class2 , T Type2;
};

MyStruct<Class1 >::Type1 MyTypedef1 ;
MyStruct<Class2 >::Type2 MyTypedef2 ;
Should have been posted as:

template<class T>
struct MyStruct
{
typedef Periodic<Class1 , T Type1 ;
typedef Periodic<Class2 , T Type2 ;
};

MyStruct<double MyTypedef1 ;
MyStruct<double MyTypedef2 ;
Apr 12 '07 #4
2b|!2b==? wrote:
Correction:

This :
>template<cla ss T>
struct MyStruct
{
typedef Periodic<Class1 , T Type1;
typedef Periodic<Class2 , T Type2;
};

MyStruct<Class 1>::Type1 MyTypedef1 ;
MyStruct<Class 2>::Type2 MyTypedef2 ;

Should have been posted as:

template<class T>
struct MyStruct
{
typedef Periodic<Class1 , T Type1 ;
typedef Periodic<Class2 , T Type2 ;
};

MyStruct<double MyTypedef1 ;
MyStruct<double MyTypedef2 ;
You probalby meant

typedef MyStruct<double >::Type1 MyTypedef1;
typedef MyStruct<double >::Type2 MyTypedef2;

otherwise they are object declarations.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 12 '07 #5


Victor Bazarov wrote:

>
You probalby meant

typedef MyStruct<double >::Type1 MyTypedef1;
typedef MyStruct<double >::Type2 MyTypedef2;

otherwise they are object declarations.

V
Doh !
Of course, you're right - thanks for pointing out my glaring mistake -
time for a fresh cup of coffee maybe ? :P
Apr 13 '07 #6
2b|!2b==? wrote:
Victor Bazarov wrote:

>>
You probalby meant

typedef MyStruct<double >::Type1 MyTypedef1;
typedef MyStruct<double >::Type2 MyTypedef2;

otherwise they are object declarations.

V

Doh !
Of course, you're right - thanks for pointing out my glaring mistake -
time for a fresh cup of coffee maybe ? :P
<shrug>

Either way, ou're not winning anything. You could do

template<class Tstruct Periodic1 {
typedef Periodic<Class1 ,Ttype;
};

and then use it to declare objects this way:

Periodic1<doubl e>::type blah;

instead of remembering

Periodic<Class1 ,doubleblah;

But I don't see much difference. You could of course use 'Periodic1'
(or 'MyStruct') inside another template... Again, not much better
than spelling it out.

I think template typedefs are coming in the next revision of the
language, though.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 13 '07 #7
Without actually checking it ...

Wouldn't it be sufficient to say

template <typename T>
typedef typename Periodic<Class1 , TCP1;

Apr 15 '07 #8
Amit Gupta wrote:
Without actually checking it ...

Wouldn't it be sufficient to say

template <typename T>
typedef typename Periodic<Class1 , TCP1;
No. Template typedefs are currently illegal. You need to put them
inside a class template or struct template.
Apr 15 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2115
by: Nicola | last post by:
Consider the following implementation of a graph, whose nodes must be of type Node or of a subclass of Node: class Node { public: Node(Data* d) { adjList = new vector<Node*>; data = d; } virtual ~Node() { delete adjList; } virtual void addNode(Data* d) { /*...*/ } void connectToNode(Node* n) { adjList->push_back(n); } Node* getChild(int i) const { return adjList->at(i); }
1
1661
by: Alexander Stippler | last post by:
Hello, I have some template class, where I want to initialize an array with some default value depending on a template parameter. Therefore I have some traits class. Just like this: template <typename T> DenseVector<T>::DenseVector(long size) { _allocate(); // allocate memory;
3
1700
by: Ruben Campos | last post by:
I have a template class, and I want to create partially (totally) specialized versions of it, by adding new methods to the original base template specification. But it seems that partially (totally) specialized templates are completely independent from their base templates, so in order to do what I want, I have to redeclare and redefine (in both cases duplicating code) all methods and attributes of the base template in each of the...
2
6207
by: Hartmut Sbosny | last post by:
Hello NG, I have a question. I have a header file with a function template and a fully specialized version of it, for instance //======== File "templ.hpp" ======== #include <iostream> // the general function template... template <class T>
3
1962
by: BigMan | last post by:
Why cannot I define a member of an explicitly specialized class template out of the class template specialization: template< int i > struct a { static void Do( ); }; template< >
2
3740
by: Aarti | last post by:
Say I have a class template as follows template<typename T> class foo { public: void test(); }; template<typename T>
2
1880
by: Olaf | last post by:
Hi, I'm working on a thin libcurl layer. Therefore I have the following classes: template<typename T, long CURLOPT_ID> class CurlOption: boost::noncopyable { public: typedef typename boost::call_traits<T>::param_type param_type; .... public:
2
1322
by: skydoom | last post by:
template <class A, class B> inline B* mycast( A* a) { return dynamic_cast<B>(a); } // try to specialize the mycast to handle when B==A, such as: template <class A> inline A* mycast(A* a) { return a; // since type B is identical to A. }
1
2219
by: jason.cipriani | last post by:
Here is an example with 3 files, containing a template structure and also a template function. The header A.h declares a template structure A with a default (i.e. for any template parameter), inlined constructor implementation, and also declares a template function f. The file main.cpp contains some test code and also the default implementation for f(). The file spec.cpp contains some explicitly specialized stuff: ==== A.h ====
0
10193
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
10005
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
11620
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
11393
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
10717
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8296
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
6246
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6371
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3572
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.