mirror of
https://gitlab.com/fbb-git/cppannotations
synced 2024-11-16 07:48:44 +01:00
Francesco Poli's remarks processed
git-svn-id: https://cppannotations.svn.sourceforge.net/svnroot/cppannotations/trunk@474 f6dd340e-d3f9-0310-b409-bdd246841980
This commit is contained in:
parent
5678d75fe4
commit
bed16d2d1b
3 changed files with 10 additions and 10 deletions
|
@ -73,12 +73,12 @@ something inside a class
|
|||
char const * (String::*sp)() const;
|
||||
)
|
||||
Nothing forces us to define pointers to members in their target
|
||||
(tt(String)) classes. Pointers to members em(may) be defined in its target
|
||||
class (so it becomes a data member), or in another class, or as a local
|
||||
(tt(String)) classes. Pointers to members em(may) be defined in their target
|
||||
classes (so they become data members), or in another class, or as a local
|
||||
variable or as a global variable. In all these cases the pointer to member
|
||||
variable can be given the address of the kind of member it points to. The
|
||||
important part is that a pointer to member can be initialized or assigned
|
||||
without requiring the existence an object of the pointer's target class.
|
||||
without requiring the existence an object of the pointer's target class.
|
||||
|
||||
Initializing or assigning an address to such a pointer merely indicates to
|
||||
which member the pointer points. This can be considered some kind of
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
}
|
||||
|
||||
/*
|
||||
generated output:
|
||||
generated output (on 32-bit architectures):
|
||||
|
||||
size of pointer to data-member: 4
|
||||
size of pointer to member function: 8
|
||||
|
|
|
@ -15,7 +15,7 @@ dereference operation is used to reach the function or variable the pointer to
|
|||
member points to.
|
||||
|
||||
Using the example from the previous section, let's see how we can use
|
||||
pointers to members function and pointers to data members:
|
||||
pointers to member functions and pointers to data members:
|
||||
verbinclude(pointermembers/examples/using.cc)
|
||||
We note:
|
||||
itemization(
|
||||
|
@ -73,18 +73,18 @@ database class. A standard implementation of this class could be:
|
|||
}
|
||||
)
|
||||
Although it doesn't take much time, the tt(switch) must nonetheless be
|
||||
evaluated every time tt(personInfo()) is called. Instead of using a switch, we
|
||||
evaluated every time tt(personInfo) is called. Instead of using a switch, we
|
||||
could define a member tt(d_infoPtr) as a pointer to a member function of the
|
||||
class tt(PersonData) returning a tt(string) and expecting a tt(Person)
|
||||
reference as its argument.
|
||||
class tt(PersonData) returning a tt(string) and expecting a pointer to a
|
||||
tt(Person) as its argument.
|
||||
|
||||
Instead of evaluating the switch this pointer can be used to point to
|
||||
tt(allInfo), tt(noPhone) or tt(nameOnly). Furthermore, the member function
|
||||
the pointer points to will be known by the time the tt(PersonData)
|
||||
object is constructed and so its value needs to be determined only once (at
|
||||
the PersonData) object's construction time.
|
||||
the PersonData object's construction time).
|
||||
|
||||
Having initialized tt(d_infoPtr) tt(personInfo()) member function is now
|
||||
Having initialized tt(d_infoPtr) the tt(personInfo) member function is now
|
||||
implemented simply as:
|
||||
verb(
|
||||
string PersonData::personInfo(char const *name)
|
||||
|
|
Loading…
Reference in a new issue