473,387 Members | 1,456 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,387 software developers and data experts.

"typedef templates" inside templates - how can I do this?

I'm aware, that up to date, "typedef templates" are not defined within
the C++ standard. The seemingly common workaround is this:
template <class T> struct MyTypeDef
{
/* ultimately I need something like this:
MyOtherClass<T> Type;
but let's keep it simple for the moment */

typedef short Type;
};

// I now can use this pseudo typedef template like this:

MyTypeDef<int>::Type foo;
// but this does not compile (MSVC):

template <class T> class MyClass {
MyTypeDef<T>::Type foo;
};
Is there a typo in my code, or is there some fundamental limitation that
prohibits the typedef template workaround in this situation?

-Sacha
Dec 6 '05 #1
4 2447

Sacha wrote:
I'm aware, that up to date, "typedef templates" are not defined within
the C++ standard. The seemingly common workaround is this:
template <class T> struct MyTypeDef
{
/* ultimately I need something like this:
MyOtherClass<T> Type;
but let's keep it simple for the moment */

typedef short Type;
};

// I now can use this pseudo typedef template like this:

MyTypeDef<int>::Type foo;
// but this does not compile (MSVC):

template <class T> class MyClass {
MyTypeDef<T>::Type foo;
typename MyTypeDef<T>::Type foo;
};


Gavin Deane

Dec 6 '05 #2
"Sacha" <sa**********@unibas.ch> wrote in message
news:43**************@unibas.ch
I'm aware, that up to date, "typedef templates" are not defined within
the C++ standard. The seemingly common workaround is this:
template <class T> struct MyTypeDef
{
/* ultimately I need something like this:
MyOtherClass<T> Type;
but let's keep it simple for the moment */

typedef short Type;
};

// I now can use this pseudo typedef template like this:

MyTypeDef<int>::Type foo;
// but this does not compile (MSVC):

template <class T> class MyClass {
MyTypeDef<T>::Type foo;
};


Make that

template <class T> class MyClass {
typename MyTypeDef<T>::Type foo;
};
--
John Carson
Dec 6 '05 #3

Sacha wrote:

template <class T> class MyClass {
MyTypeDef<T>::Type foo;
typename MyTypeDef<T>::Type foo;

This will work.
Is there a typo in my code, or is there some fundamental limitation that
prohibits the typedef template workaround in this situation?
Not a typo really. But typenames inside template qualified with the
template parameter must be accompanied by the keyword "typename", else
they will be treated as static variables.

-Sacha


Dec 6 '05 #4
Sacha wrote:
I'm aware, that up to date, "typedef templates" are not defined within
the C++ standard. The seemingly common workaround is this:
template <class T> struct MyTypeDef
{
/* ultimately I need something like this:
MyOtherClass<T> Type;
but let's keep it simple for the moment */

typedef short Type;
// Should that be
typedef T Type;
};

// I now can use this pseudo typedef template like this:

MyTypeDef<int>::Type foo;
// but this does not compile (MSVC):

template <class T> class MyClass {
MyTypeDef<T>::Type foo;
// Have to let the compiler know about the dependant type.
typename MyTypeDef<T>::Type foo;
};
Is there a typo in my code, or is there some fundamental limitation that
prohibits the typedef template workaround in this situation?


Does that sort you out?

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Dec 6 '05 #5

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

Similar topics

6
by: Fao | last post by:
Hi, I am in my first year of C++ in college and my professor wants me to Write a Program with multiple functions,to input two sets of user-defined data types: One type named 'Sign' declared by...
1
by: Joel Kullberg | last post by:
Hi! I have a question for u guys! I would like to use the c++ package ITK (www.itk.org) for internal handling och data and functions in a dataset3D class of mine! I also want to use a base...
6
by: hercules | last post by:
Hi: In some code , I used typedef unsigned char BOOL; /*boolean */ But in other code , I must use typedef unsigned int BOOL; /* boolean */ How to remove the previous typedef ? ...
1
by: Thomas Barnet-Lamb | last post by:
I was wondering if anyone could give me some help with the following. Consider the code snippet: struct qqq{typedef qqq* pointer;}; template<class al> struct foo : public al { template...
134
by: jacob navia | last post by:
Hi Suppose you have somewhere #define BOOL int and somewhere else typedef BOOL int;
7
by: for.fun | last post by:
Hi everybody, I have the following problem : B class need A::MyEnum type and A class need B::MyEnum type. In both case, the class type is incomplete so it is obvious that the ::MyEnum can not...
8
by: Mohammad Omer Nasir | last post by:
Hi, i made a structure in header file "commonstructs.h" is: typedef struct A { int i; A( ) {
8
by: cman | last post by:
What does this kind of typedef accomplish? typedef struct { unsigned long pte_low; } pte_t; typedef struct { unsigned long pgd; } pgd_t; typedef struct { unsigned long pgprot; } pgprot_t I am...
4
by: msukumarbabu | last post by:
Hi all, What will be difference between "typedef enum" and "enum". or difference between “typedef structure" and "structure" I am going through some code. in that some place they are using...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...

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.