Is this legal C++?

Zack Weinberg zack@wolery.cumb.org
Wed Apr 19 14:08:00 GMT 2000


Consider this fragment:

class C {
	private:
	void (C::*oper) (int, int);

	public:
	void operate (int, int);
};

void
C::operate (int x, int y)
{
  C::oper (x, y);
}

G++ gives me the following error:

test.cc: In method `void C::operate (int, int)':
test.cc:12: pointer-to-member function this->C::oper cannot be called
test.cc:12: without an object; consider using .* or ->*

which is telling me that I should have written

  (this->*C::oper) (x, y);

Now I find this somewhat surprising.  Why doesn't the "implicit this"
syntactic sugar extend to an implicit ->* for references to
pointer-to-member-function members?

I can't find anything relevant in the standard.

Also, note that G++ insists on the first pair of parentheses;

  this->*C::oper (x, y);

gets the same error.

[In case anyone's wondering, I'm trying to figure out if
g++.robertl/eb127.C is ill-formed code.  It has a very similar
construct.]

zw


More information about the Gcc mailing list