From bed16d2d1b59f05660bd126557d3ddd6fa805b39 Mon Sep 17 00:00:00 2001 From: "Frank B. Brokken" Date: Thu, 2 Sep 2010 14:23:08 +0000 Subject: [PATCH] Francesco Poli's remarks processed git-svn-id: https://cppannotations.svn.sourceforge.net/svnroot/cppannotations/trunk@474 f6dd340e-d3f9-0310-b409-bdd246841980 --- yo/pointermembers/defining.yo | 6 +++--- yo/pointermembers/examples/size.cc | 2 +- yo/pointermembers/using.yo | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/yo/pointermembers/defining.yo b/yo/pointermembers/defining.yo index 148975f1..3a571417 100644 --- a/yo/pointermembers/defining.yo +++ b/yo/pointermembers/defining.yo @@ -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 diff --git a/yo/pointermembers/examples/size.cc b/yo/pointermembers/examples/size.cc index 978a1fed..013b4b2d 100644 --- a/yo/pointermembers/examples/size.cc +++ b/yo/pointermembers/examples/size.cc @@ -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 diff --git a/yo/pointermembers/using.yo b/yo/pointermembers/using.yo index 0930e14b..e1e3e2a7 100644 --- a/yo/pointermembers/using.yo +++ b/yo/pointermembers/using.yo @@ -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)