Pointer-to-member operator and member functions

Jonathan M. Gilligan (jonathan.gilligan@vanderbilt.edu)
Tue, 21 Jul 1998 11:17:44 -0500


I need to have a function that accesses an arbitrary member function of a
class through a pointer (I need to integrate member functions and don't
want to write a separate integration routine for each function that I want
to integrate. I can't use the TF1::Integrate because the functions I need
to integrate are pure virtual member functions of an abstract base class.
The ARM indicates that the right way to go with this in standard C++ is to
use the pointer-to-member operators .* and ->* (ARM section 5.5). However,
CINT does not seem to implement these operators (see test program below).

I would like to request that a future release implement these operators and
to ask whether there is a workaround. Can I call a member function of a
class through a pointer in CINT?

The following program runs perfectly under my regular C++ compiler (M'Soft
VC++ 5.0 SP3). However under Root's CINT I get these error messages:

Error: No symbol foo::f in current scope FILE:boo.cpp LINE:56
Error: class,struct,union or type fu.*fn not defined FILE:boo.cpp LINE:47
Error: No symbol foo::g in current scope FILE:boo.cpp LINE:57
Error: class,struct,union or type fu.*fn not defined FILE:boo.cpp LINE:47

//====================== boo.cpp ========================
class foo
{
private:
public:
foo();
~foo();
virtual double f(double x) const;
virtual double g(double x) const;
};

class bar
{
public:
bar();
~bar();
double sqr(const foo& fu, double (foo::*fn)(double) const, double x) const;
};

foo::foo()
{
}

foo::~foo()
{
}

double foo::f(double x) const
{
return x + 1.0;
}

double foo::g(double x) const
{
return 2.0 * x;
}

bar::bar()
{
}

bar::~bar()
{
}

double bar::sqr(const foo& fu, double (foo::*fn)(double) const, double x)
const
{
double y = (fu.*fn)(x); // CINT does not seem to understand the .*
operator here
return y * y;
}

void boo ()
{
bar b;
foo ff;

b.sqr(ff,foo::f,2.0); // CINT does not understand foo::f (ptr to member
function)
b.sqr(ff,foo::g,2.0); // CINT does not understand foo::g
}
//===================================== end of boo.cpp
=================================
===========================================================================
Jonathan M. Gilligan <jonathan.gilligan@vanderbilt.edu>
Research Assistant Professor and Associate Director (615) 343-2957
Center for Molecular and Atomic Studies at Surfaces Fax: 343-1708
Dept. of Physics and Astronomy, Box 1807-B Sec'y 322-6438
Vanderbilt University, Nashville, TN 37235 Lab: 343-7578