Jerry Feldman wrote:
On Sunday 21 August 2005 3:51 pm, John D Lamb wrote:
Here's a puzzle: I'd like to define something like
typedef std::pair<int,P*> P;
I can obviously do
class P : public std::pair<int,P*>{};
or
typedef std::pair<int,void*> P; In this case, you have not yet defined P. You could use a forward declaration, such as: class P; Then, typedef std::pair<int,P*> P; should work. I have not tried your example specifically.
Sadly it doesn't work though I actually had to try this to see. It does confirm that I'm not being totally stupid in thinking that C++ might reasonably allow this sort of thing. The C++ standard doesn't allow you to use typedef for a name already declared in the same scope. I think C++ won't allow you to do something like: class X<X*> x; i.e. create a template class whose template parameter is a pointer to an object of this class. It will allow class Y : public class X<Y*> {} x; which is nearly the same. For my own problem, I've worked out I can use static_cast rather than reinterpret_cast, which is a bit of an improvement. -- JDL