Solved

typedef for a template class with a template class as param

Posted on 2004-09-01
4
212 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ assignment question 7 237
how to convert c++ code to Android App 3 109
Add values of each row in an array 3 64
Safe conversion? 4 72
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

830 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