Chapter 23. Template Constructors
An obvious disadvantage of bolt-ins, veneers, and other templates that derive from their parameterizing type(s), is that they hide that type's constructors. Consider the hypothetical classes in Listing 23.1.
Example 23.1.
class Double
{
public:
typedef double value_type;
public:
Double();
explicit Double(double d);
public:
double GetValue() const;
. . .
};
template <typename T>
class Wrapper
: public T
{
. . .
};
typedef Wrapper<Double> Double_t;
Double_t d1;
Double_t d2(12.34); // Error!
Wrapper
has effectively hidden the second constructor of Double
, so the attempt to nondefault construct it is an error.
The method of solving this problem for Microsoft's Active Template Library (ATL) is to avoid it. CComObject ...
Get Imperfect C++ Practical Solutions for Real-Life Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.