33 #include <Base/Common/SharedPtr.hh>
51 std::ostream&
operator<<(std::ostream& os,
const foo& arg)
52 { os << arg.i<<
" "<<arg.d;
return os; }
55 class uta :
public foo {
61 std::ostream&
operator<<(std::ostream& os,
const uta& arg)
62 { os << arg.i<<
" "<<arg.d<<
" "<<arg.name;
return os; }
66 int main(
int argc,
char *argv[])
72 cout <<
"reference count of p_foo: "<<
RefCount(p_foo)<<endl;
78 cout <<
"content of p_foo: "<<*p_foo<<endl;
84 cout <<
"simple test for NULL pointer : (p_foo2) \n"
85 <<
"content of p_foo2: "<<*p_foo2<<endl;
92 cout <<
"p_foo and p_foo2 point ot the same object: reference count "
95 cout <<
"this cannot happen\n";
99 cout <<
"re-assigned p_foo2: reference count "<<
RefCount(p_foo)<<endl;
105 pc_foo = ConstCast<const foo>(p_foo);
110 p_uta->name=
"diogenes";
113 p_foo2 = DynamicCast<foo>(p_uta);
115 cout <<
"p_uta and p_foo2 point to the same object: ref count "
117 <<
" content of p_foo2: "<<*p_foo2<<endl;
119 cerr <<
"this will not happen\n";
123 cout <<
"*p_uta2: "<<*p_uta2<<endl;
pointer with reference count and automatic deletion
unsigned RefCount(const SharedPtr< T > &t)
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)