[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
C++ class pointers to member function Help
From: |
swagat |
Subject: |
C++ class pointers to member function Help |
Date: |
12 Feb 2006 02:57:21 -0800 |
User-agent: |
G2/0.2 |
Hi!
I want to do something like this:
test.cpp
----------------
class abc{
int i;
double a;
public:
double (*f)(double x);
double func1(double x);
double func2 (double y);
void update(double x1);
};
void update(double x)
{
switch(i){
case 1:
f=func1;
break;
case 2:
f=func2;
break;
}
}
---------------------------------------------
First of all, I am aware of the pointer to class member functions. But
that requires explicit knowledge of object. There we do something like
this:
int main()
{
double x=3.0;
double (abc::*fn)(double x);
abc b1;
fn=&abc::func1();
cout<<(b1.*fn)(double x);
}
But this is not what I want to do. First of all, I am accessing one
member function by another member function where object declaration is
not required. I want to use a pointer to access the other member
functions within the class as demonstrated above. Is it possible to do
this?
Regards,
swagat
- C++ class pointers to member function Help,
swagat <=