 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Joe Gottman Guest
|
Posted: Tue Apr 27, 2004 12:57 am Post subject: N1618 - Template constructors of template classes |
|
|
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 |
|
 |
|
|
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
|
|