LoginSignup
0
0

More than 5 years have passed since last update.

Effective C++ (3rd) > 31項 > ハンドルクラス > クラス実装例

Last updated at Posted at 2015-05-16

引用: Effective C++ 第3版

このようなクラスで、実際に関数の定義をどう書くのかと思うかもしれませんので、まとめておきましょう。1つの方法は、対応する実装用クラスの関数を呼び出すというものです。たとえば、次のコードが、Personのクラス実装例です。

#include "Person.h"
#include "PersonImpl.h"

Person::Person(const std::string& name, const Date& birthday,
    const Address& addr)
:pImpl(new PersonImpl(name, birthday, addr))
{}

str::string Person::name() const
{
    return pImpl->name();
}

PersonのコンストラクタではPersonImplのコンストラクタを呼び出して(...)います。また、Person::nameではPersonImpl::nameを呼び出しています。これは重要です。PersonをハンドルにしてもPersonのすることは変更されません。その仕方が変わるだけなのです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0