DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Please Help : ... Function Pointer in a Class ...

  1. #1
    Guest

    Please Help : ... Function Pointer in a Class ...

    Hello everybody,

    I hope someone one could help me. here is the problem :
    _______________________________________________________________________

    class CclassB :
    {
    public:
    void (*fonction2) (double, double);
    }
    ________________________________________________________________________

    class CclassA :
    {
    public:
    CclassA()
    {
    CtheclassInside = new CclassB;
    CtheclassInside->fonction2 = fonction1;
    }
    CclassB* CtheclassInside;
    void fonction1 (double, double);
    }
    _______________________________________________________________________

    I have 2 classes, one 'CclasseB' exist in 'CclassA', and i want to use the
    fonction 'fonction1' of 'CclassA' in the classe 'CclasseB'. I'v got the
    error :

    ____________________________________________________________________________
    ______________________

    error C2440: '=' : cannot convert from 'void (__thiscall CclassA
    ::*)(double,double)' to 'void (__cdecl *)(double,double)'
    ____________________________________________________________________________
    _______________________


    Have you got any idea ? the msdn help is not really clear, i have made a lot
    of tries but no issue ....

    Thank's for your time ...

    Driss






  2. #2
    Ralph D. Cole Guest

    Re: Please Help : ... Function Pointer in a Class ...


    <ndriss@club-internet.fr> wrote:
    >Hello everybody,
    >
    >I hope someone one could help me. here is the problem :
    >_______________________________________________________________________
    >
    >class CclassB :
    >{
    >public:
    >void (*fonction2) (double, double);
    >}
    >________________________________________________________________________
    >
    >class CclassA :
    >{
    >public:
    > CclassA()
    > {
    > CtheclassInside = new CclassB;
    > CtheclassInside->fonction2 = fonction1;
    > }
    > CclassB* CtheclassInside;
    > void fonction1 (double, double);
    >}
    >_______________________________________________________________________
    >
    >I have 2 classes, one 'CclasseB' exist in 'CclassA', and i want to use the
    >fonction 'fonction1' of 'CclassA' in the classe 'CclasseB'. I'v got the
    >error :
    >
    >____________________________________________________________________________
    >______________________
    >
    >error C2440: '=' : cannot convert from 'void (__thiscall CclassA
    >::*)(double,double)' to 'void (__cdecl *)(double,double)'
    >____________________________________________________________________________
    >_______________________
    >
    >
    >Have you got any idea ? the msdn help is not really clear, i have made a

    lot
    >of tries but no issue ....
    >
    >Thank's for your time ...
    >
    >Driss
    >


    First, a member function contains a hidden argument, the this* pointer to
    the class. Also a member function is _stdcall and you have declared it as
    cdecl. Look at the error message carefully and you will see your "function
    pointer" declaration is wrong.

    One way out is to declare the function as static.

    Second, outside of a few exotic hacks, this is seldom a good idea. If you
    are using the 'services' of a class, import the class, not pieces of it.

  3. #3
    www.exontrol.com Guest

    Re: Please Help : ... Function Pointer in a Class ...


    typedef

    Mike
    www.exontrol.com
    <ndriss@club-internet.fr> wrote:
    >Hello everybody,
    >
    >I hope someone one could help me. here is the problem :
    >_______________________________________________________________________
    >
    >class CclassB :
    >{
    >public:
    >void (*fonction2) (double, double);
    >}
    >________________________________________________________________________
    >
    >class CclassA :
    >{
    >public:
    > CclassA()
    > {
    > CtheclassInside = new CclassB;
    > CtheclassInside->fonction2 = fonction1;
    > }
    > CclassB* CtheclassInside;
    > void fonction1 (double, double);
    >}
    >_______________________________________________________________________
    >
    >I have 2 classes, one 'CclasseB' exist in 'CclassA', and i want to use the
    >fonction 'fonction1' of 'CclassA' in the classe 'CclasseB'. I'v got the
    >error :
    >
    >____________________________________________________________________________
    >______________________
    >
    >error C2440: '=' : cannot convert from 'void (__thiscall CclassA
    >::*)(double,double)' to 'void (__cdecl *)(double,double)'
    >____________________________________________________________________________
    >_______________________
    >
    >
    >Have you got any idea ? the msdn help is not really clear, i have made a

    lot
    >of tries but no issue ....
    >
    >Thank's for your time ...
    >
    >Driss
    >
    >
    >
    >
    >



  4. #4
    Danny Kalev Guest

    Re: Please Help : ... Function Pointer in a Class ...

    you want to read more about pointers to member functions and how they
    differ from ordinary pointers to functions. Secondly, as Ralph said,
    importing a piece of a class is rarely a good idea.
    http://gethelp.devx.com/techtips/cpp...0minJuly98.asp

    Danny

    ndriss@club-internet.fr wrote:
    >
    > Hello everybody,
    >
    > I hope someone one could help me. here is the problem :
    > _______________________________________________________________________
    >
    > class CclassB :
    > {
    > public:
    > void (*fonction2) (double, double);
    > }
    > ________________________________________________________________________
    >
    > class CclassA :
    > {
    > public:
    > CclassA()
    > {
    > CtheclassInside = new CclassB;
    > CtheclassInside->fonction2 = fonction1;
    > }
    > CclassB* CtheclassInside;
    > void fonction1 (double, double);
    > }
    > _______________________________________________________________________
    >
    > I have 2 classes, one 'CclasseB' exist in 'CclassA', and i want to use the
    > fonction 'fonction1' of 'CclassA' in the classe 'CclasseB'. I'v got the
    > error :
    >
    > ____________________________________________________________________________
    > ______________________
    >
    > error C2440: '=' : cannot convert from 'void (__thiscall CclassA
    > ::*)(double,double)' to 'void (__cdecl *)(double,double)'
    > ____________________________________________________________________________
    > _______________________
    >
    > Have you got any idea ? the msdn help is not really clear, i have made a lot
    > of tries but no issue ....
    >
    > Thank's for your time ...
    >
    > Driss


  5. #5
    cme Guest

    Re: Please Help : ... Function Pointer in a Class ...


    As mentioned before member functions have a "hidden" this pointer but it seems
    to me that the approach is questionable. A simpler solution would be to
    inherit class A from B. Then you can call function in B from A.

    <ndriss@club-internet.fr> wrote:
    >Hello everybody,
    >
    >I hope someone one could help me. here is the problem :
    >_______________________________________________________________________
    >
    >class CclassB :
    >{
    >public:
    >void (*fonction2) (double, double);
    >}
    >________________________________________________________________________
    >
    >class CclassA :
    >{
    >public:
    > CclassA()
    > {
    > CtheclassInside = new CclassB;
    > CtheclassInside->fonction2 = fonction1;
    > }
    > CclassB* CtheclassInside;
    > void fonction1 (double, double);
    >}
    >_______________________________________________________________________
    >
    >I have 2 classes, one 'CclasseB' exist in 'CclassA', and i want to use the
    >fonction 'fonction1' of 'CclassA' in the classe 'CclasseB'. I'v got the
    >error :
    >
    >____________________________________________________________________________
    >______________________
    >
    >error C2440: '=' : cannot convert from 'void (__thiscall CclassA
    >::*)(double,double)' to 'void (__cdecl *)(double,double)'
    >____________________________________________________________________________
    >_______________________
    >
    >
    >Have you got any idea ? the msdn help is not really clear, i have made a

    lot
    >of tries but no issue ....
    >
    >Thank's for your time ...
    >
    >Driss
    >
    >
    >
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center