Topic: Invoke through pointer to member without 'this'?


Author: kanze@us-es.sel.de (James Kanze)
Date: 8 Nov 93 19:31:54
Raw View
In article <NEAL.93Nov4153944@neal.ctd.comsat.com> neal@ctd.comsat.com
(Neal Becker) writes:

|> At g++-2.4.5 this worked:

|> class a {
|>   void (a::*b)(int,int);
|>   void c();
|> };

|> a::c() {
|>   b(1,2);
|> }

|> But now it needs to be written like this:

|> a::c() {
|>   (this->*b)(1,2);
|> }

|> Does ARM say anything about this?  Is the latter the only correct
|> method?  I sure hope not.  This is ugly (and not consistent with
|> expected behaviour IMHO).

g++ (at least 2.4.5) is wrong.  The second way you write it is
correct.

Note that since the variable 'b' is a member, inserting the implicit
'this->' in front of 'b' would give:

 this->b( 1 , 2 ) ;

But what is this supposed to mean?  'this->b' is a pointer to member,
and must be dereferenced to be used.

The two legal expressions:

 (this->*b)( 1 , 2 ) ;  //  with implicit this
 (this->*(this->b))( 1 , 2 ) ; //  with explicit this
--
James Kanze                             email: kanze@us-es.sel.de
GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France
Conseils en informatique industrielle --
                   -- Beratung in industrieller Datenverarbeitung




Author: pkt@lpi.liant.com (Scott Turner)
Date: Mon, 8 Nov 1993 19:33:52 GMT
Raw View
In article <NEAL.93Nov4153944@neal.ctd.comsat.com>, neal@ctd.comsat.com (Neal Becker) writes:
> At g++-2.4.5 this worked:
>
> class a {
>   void (a::*b)(int,int);
>   void c();
> };
>
> a::c() {
>   b(1,2);
> }
>
> But now it needs to be written like this:
>
> a::c() {
>   (this->*b)(1,2);
> }
>
> Does ARM say anything about this?  Is the latter the only correct
> method?

The ARM says nothing about the former.  Yes, only the latter is correct.
--
Prescott K. Turner, Jr.
Liant Software Corp. (developers of LPI languages)
959 Concord St., Framingham, MA 01701 USA    (508) 872-8700
UUCP: uunet!lpi!pkt                          Internet: pkt@lpi.liant.com





Author: neal@ctd.comsat.com (Neal Becker)
Date: 04 Nov 1993 20:39:44 GMT
Raw View
At g++-2.4.5 this worked:

class a {
  void (a::*b)(int,int);
  void c();
};

a::c() {
  b(1,2);
}

But now it needs to be written like this:

a::c() {
  (this->*b)(1,2);
}

Does ARM say anything about this?  Is the latter the only correct
method?  I sure hope not.  This is ugly (and not consistent with
expected behaviour IMHO).