menu

hjk41的日志

Avatar

Effecitve C++ 50: Improve your understanding of C++

With this item comes the end of Effective C++ 2nd Edition, a book I have read for over 3 months. I have learnt a lot from this book, and hope you too.

There are several books I want to read next:
More Effective C++
The Design and Evolution of C++
The Annotated C++ Reference Manual
The International Standards of C++
I already have an html edition of More Effective C++, and the C++ standard can be downloaded from ISO web site. However, I still can't find the electronic edition of the other two.

At last, several lines of code:

class Base {
public:
  virtual void f(int x);
};

class Derived: public Base {
public:
  virtual void f(double *pd);
};

Derived *pd = new Derived;
pd->f(10);                            // error!


Derived::f() will always hide Base::f() given that the pointer you invoke f() with is of type Derived *. To use Base::f(), you can simply say this:

class Derived: public Base {
public:
  using Base::f;                   // import Base::f into
                                   // Derived's scope
  virtual void f(double *pd);
};

Derived *pd = new Derived;
pd->f(10);                         // fine, calls Base::f

评论已关闭