Solved

typedef for a template class with a template class as param

Posted on 2004-09-01
4
209 Views
Last Modified: 2010-04-01
Good Morning,

I would like to know if there is a way that I can create a typedef for a template class that has another template in it with a variable type parameter.

for example

template<class T> class Outer{...};
template<class T> class Inner{...};

typedef Outer< Inner<class T> > NewClass;

NewClass<int> getClass() {
}

I have tried this with GCC and it tells me the "NewClass" type is not a template, therefore I cannot pass a parameter to it.

I do not want to use the proprocessor.

Thank you,
- Dave
0
Comment
Question by:illusioned
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 11952644
You can't - see e.g. http://www.gotw.ca/gotw/079.htm ("Template Typedef") - the key sentence is "the code in question above isn't legal for a simple reason: Today's C++ doesn't support template typedefs.". The article also offers an alternative solution.
0
 
LVL 4

Expert Comment

by:havman56
ID: 11952847

This works fine on MSC

template<class T>
class Outer{

      public:
      void getClass();
      
};

template<class T>
class Inner{
      };


template <class T>
void Outer<T>:: getClass()
{


}


main()
{
      typedef Outer< Inner <int> > NewClass;

      NewClass  obj;
      obj.getClass();

}
0
 

Author Comment

by:illusioned
ID: 11953289
Thanks JKR.  

From other things that I have read this may be appearing in standard C++ in the future.  In light of this, I may end up using the preprocessor just so that I won't have to change my code when it is supported by GCC (it may even be now, but I am going to stick with GCC 3.2.3).


Thank you for the help.
- Dave
0
 
LVL 86

Expert Comment

by:jkr
ID: 11959253
You're most welcome :o)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now