On 24 mar, 11:48, SG <s.gesem...@gmail.com> wrote:
On 24 Mrz., 10:54, Michael Doubez wrote:
(2)
template<class T>
struct ForceType { };
struct X
{
template <class T, class F >
X( T* p , const ForceType<F>& force_type = ForceType<T>() )
{
F* pf = p;//...
}
};
X x(&d,ForceType<Base>());
The default parameter doesn't work here. At least G++ is rejecting it
and I think this is because F cannot be deduced by the default
parameter.
Yes.
=A714.8.2/17: a template type-parameter cannot be deduced from the type
of a function default argument.
[snip]
But I honestly see no advantage over
struct X
{
template <class T>
X(T*);
};
X x(static_cast<base*>(&d));
From the very beginning the question is biased: if you have a template
argument, I don't the reason why you would want to instantiate it with
a base class.
Unless the member function became protected in the derived but then
the cast should obviously be explicit.
--
Michael