Topic: pointers to methods


Author: rjiang@lcpd2 (Roger Jiang (Intern))
Date: 1995/04/14
Raw View
Franck Valentin (fvalenti@ifremer.fr) wrote:

| I would like to resolve this problem :
| I have an object 'Object' with 2 methods F1,F2


| void Object::F1(data*,void*) {..}

| void Object::F2()
|  {
|  void (*ptrToFunction)(data*,void*);

Is it correct?

 void (Object::*ptrToFunction)(data*, void*);

I think it works.

|  pointerToFunction = F1;    // (1)
|  InsideObject.apply(ptrToFunction);
|  ..
|  }
| But the compiler print 'can't convert (Object::*)(data*,void*) to void(*)(data*,void*)' at line (1)

| I cant't define ptrToFunction as '(Object::*ptrToFunction(data*,void*)' because the method 'apply'
| needs 'void (*ptrToFunction)(data*,void*)' !

| Who can't help me ?
|     Thanks.

| (I'm a beginner in and in C++ and in english too !..)






--
Roger Jiang





Author: rjiang@lcpd2 (Roger Jiang (Intern))
Date: 1995/04/14
Raw View
Franck Valentin (fvalenti@ifremer.fr) wrote:

| I would like to resolve this problem :
| I have an object 'Object' with 2 methods F1,F2


| void Object::F1(data*,void*) {..}

| void Object::F2()
|  {
|  void (*ptrToFunction)(data*,void*);

|  pointerToFunction = F1;    // (1)
|  InsideObject.apply(ptrToFunction);
|  ..
|  }
| But the compiler print 'can't convert (Object::*)(data*,void*) to void(*)(data*,void*)' at line (1)

| I cant't define ptrToFunction as '(Object::*ptrToFunction(data*,void*)' because the method 'apply'
| needs 'void (*ptrToFunction)(data*,void*)' !

| Who can't help me ?
|     Thanks.

| (I'm a beginner in and in C++ and in english too !..)

The following program is a demo and can be executed under gcc compiler.

class Object
{
public:
 int c;
 Object(void):c(0){}
 void F1(void);
 void F2(void);
};

void Object::F1(void)
{
 printf("In Object::F1()\n");
}

void Object::F2(void)
{
 void (Object::*ptrToFunc)(void) = F1;
 ptrToFunc();
}

main()
{
 Object o;
 o.F2();
}




--
Roger Jiang





Author: fvalenti@ifremer.fr (Franck Valentin)
Date: 1995/04/11
Raw View
I would like to resolve this problem :
I have an object 'Object' with 2 methods F1,F2


void Object::F1(data*,void*) {..}

void Object::F2()
 {
 void (*ptrToFunction)(data*,void*);

 pointerToFunction = F1;    // (1)
 InsideObject.apply(ptrToFunction);
 ..
 }
But the compiler print 'can't convert (Object::*)(data*,void*) to void(*)(data*,void*)' at line (1)

I cant't define ptrToFunction as '(Object::*ptrToFunction(data*,void*)' because the method 'apply'
needs 'void (*ptrToFunction)(data*,void*)' !

Who can't help me ?
    Thanks.

(I'm a beginner in and in C++ and in english too !..)