Solved

typedef for a template class with a template class as param

Posted on 2004-09-01
4
213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

738 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