Solved

typedef for a template class with a template class as param

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

910 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

22 Experts available now in Live!

Get 1:1 Help Now