mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
add * and -> operators
git-svn-id: svn+q:///qpdf/trunk@1029 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
parent
047bcfcaa6
commit
aa035961b3
@ -124,6 +124,24 @@ class PointerHolder
|
||||
return this->data->refcount;
|
||||
}
|
||||
|
||||
T const& operator*() const
|
||||
{
|
||||
return *this->data->pointer;
|
||||
}
|
||||
T& operator*()
|
||||
{
|
||||
return *this->data->pointer;
|
||||
}
|
||||
|
||||
T const* operator->() const
|
||||
{
|
||||
return this->data->pointer;
|
||||
}
|
||||
T* operator->()
|
||||
{
|
||||
return this->data->pointer;
|
||||
}
|
||||
|
||||
private:
|
||||
void init(Data* data)
|
||||
{
|
||||
|
@ -12,6 +12,7 @@ class Object
|
||||
Object();
|
||||
~Object();
|
||||
void hello();
|
||||
void hello() const;
|
||||
|
||||
private:
|
||||
static int next_id;
|
||||
@ -38,8 +39,21 @@ Object::hello()
|
||||
std::cout << "calling Object::hello for " << this->id << std::endl;
|
||||
}
|
||||
|
||||
void
|
||||
Object::hello() const
|
||||
{
|
||||
std::cout << "calling Object::hello const for " << this->id << std::endl;
|
||||
}
|
||||
|
||||
typedef PointerHolder<Object> ObjectHolder;
|
||||
|
||||
void callHello(ObjectHolder const& oh)
|
||||
{
|
||||
oh.getPointer()->hello();
|
||||
oh->hello();
|
||||
(*oh).hello();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
std::list<ObjectHolder> ol1;
|
||||
@ -74,6 +88,9 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
ol1.front().getPointer()->hello();
|
||||
ol1.front()->hello();
|
||||
(*ol1.front()).hello();
|
||||
callHello(ol1.front());
|
||||
ol1.pop_front();
|
||||
std::cout << "goodbye" << std::endl;
|
||||
return 0;
|
||||
|
@ -7,6 +7,11 @@ equal okay
|
||||
less than okay
|
||||
created Object, id 3
|
||||
calling Object::hello for 1
|
||||
calling Object::hello for 1
|
||||
calling Object::hello for 1
|
||||
calling Object::hello const for 1
|
||||
calling Object::hello const for 1
|
||||
calling Object::hello const for 1
|
||||
goodbye
|
||||
destroyed Object, id 3
|
||||
destroyed Object, id 1
|
||||
|
Loading…
Reference in New Issue
Block a user