boost::scoped_ptr
含まれているクラスの cpp ファイルにのみ表示される実装クラスでを使用しようとしています。包含クラスには明示的に定義されたデストラクタ (インラインではない) がありますが、私のコンパイラ (Borland C++ 5.6.4) はコンパイルに失敗します。
代わりに使用boost::shared_ptr
すると、同じ例が期待どおりにコンパイルおよび実行されます。
私は何を間違っていますか?
編集:ソースコード、コンパイラエラー、および(予想される)出力をここに表示するのを忘れて申し訳ありません:
ソースコード
ファイルcheck_shared.cpp
:
// shortened.
#include "SmartPtrTest.h"
void check_shared()
{
Containing t;
}
ファイルSmartPtrTest.h
:
#include <boost/noncopyable.hpp>
#include <boost/smart_ptr.hpp>
class Impl;
#define smart_ptr boost::scoped_ptr
class Containing: private boost::noncopyable
{
public:
Containing();
~Containing();
private:
smart_ptr<Impl> impl;
};
ファイルSmartPtrTest.cpp
:
#include "SmartPtrTest.h"
#include <iostream>
using namespace std;
class Impl {
public:
Impl() {
cout << "ctr Impl" << endl;
}
~Impl() {
cout << "dtr Impl" << endl;
}
};
Containing::Containing(): impl(new Impl)
{
cout << "ctr Containing" << endl;
}
Containing::~Containing()
{
cout << "dtr Containing" << endl;
}
コンパイラ エラー
...undefined structure 'Impl'
のようなものです (ドイツ語: Undefinierte Struktur 'Impl' )。ファイルをコンパイルすると、コンパイラはこの関数のファイルでcheck_shared.cpp
停止します。boost/checked_delete.hpp
typedef
template<class T> inline void checked_delete(T * x)
{
// intentionally complex - simplification causes regressions
typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
(void) sizeof(type_must_be_complete);
delete x;
}
出力(予想)
を使用したときに得られるこの出力はboost::share_ptr
、ctr と dtr が期待どおりに呼び出されることを示しています。
ctr Impl
ctr Containing
dtr Containing
dtr Impl