O'Reilly logo

Imperfect C++ Practical Solutions for Real-Life Programming by Matthew Wilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required