C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

N1618 - Template constructors of template classes

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Joe Gottman
Guest





PostPosted: Tue Apr 27, 2004 12:57 am    Post subject: N1618 - Template constructors of template classes Reply with quote



Proposal N1618 in the Post-Sydney mailing proposes a way for one constructor
to delegate to another. For instance:

class X {
int i_;
public:
X( int i ) : i_(i) { }
X() : X(42) { } // i_ == 42
};

I think this is a very good idea, but the suggested implementation runs
into a bit of a snag when a template class tries to forward to a template
constructor. The proposal gives the following example of forwarding to a
template constructor:

class X {
template<class T> X( T, T ) : l_( first, last ) { /*Common Init*/ }
list<int> l_;
public:
X( vector<short>& );
X( deque<char>& );
};
X::X( vector<short>& v ) : X( v.begin(), v.end() ) { }
// T is deduced as vector<short>::iterator
X::X( const deque<char>& d ) : X<deque( d.begin(),
d.end() ) { }
// T does not need to be deduced

But what if the class X above were a template class? In that case, would
the line

X::X( const deque<char>& d ) : X<deque( d.begin(),
d.end() ) { }

attempt to call a template constructor, or would it try to instantiate a
non-existent base class of type X<deque?

Joe Gottman



---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.