944,028 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1983
  • C RSS
Aug 3rd, 2006
0

Ask Function problem?thanks

Expand Post »
Ask Function problem?thanks
<<<<<<<<<<Class.h>>>>>>>>>>
  1. #pragma once
  2. class Class
  3. {
  4. public:
  5. int get_return(int a,int b,int (*compare)());
  6. int Rxgmoral(int a,int b);
  7. void Fun();
  8. };
<<<<<<<<<Class.Cpp>>>>>>>>
  1. #include "Stdafx.h"
  2. #include "Class.h"
  3. int Class::get_return(int a,int b,int(* compare)())
  4. {
  5. return (compare(a,b));
  6. }
  7. int Class::Rxgmoral(int a, int b)
  8. {
  9. return a+b;
  10. }
  11. void Class::Fun()
  12. {
  13. int a;
  14. a=get_return(1,2,&Rxgmoral);
  15. }
  1. error:
  2. e:\mystudio\project\test\test\class.cpp(6) : error C2197: 'int (__cdecl *)(void)' : too many arguments for call
  3. e:\mystudio\project\test\test\class.cpp(17) : error C2276: '&' : illegal operation on bound member function expression
thanks
Last edited by WolfPack; Aug 3rd, 2006 at 7:27 am.
Similar Threads
Reputation Points: 21
Solved Threads: 0
Newbie Poster
rxgmoral is offline Offline
14 posts
since Jul 2006
Aug 3rd, 2006
0

Re: Ask Function problem?thanks

try this
<<<<<<<<<<Class.h>>>>>>>>>>
 #pragma once
class Class
{
public:
    int get_return(int a,int b,int (*compare)(int, int));
    int Rxgmoral(int a,int b);
    void Fun();
};
<<<<<<<<<Class.Cpp>>>>>>>>
 #include "Stdafx.h"
#include "Class.h"
int Class::get_return(int a,int b,int(* compare)(int, int))
{
    return (compare(a,b));
}
int Class::Rxgmoral(int a, int b)
{
    return a+b;
}
void Class::Fun()
{
    int a;
    a=get_return(1,2,Rxgmoral);
}
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Aug 3rd, 2006
0

Re: Ask Function problem?thanks

Missed another one. You can't call non-static member functions like that. So change it to static.
<<<<<<<<<<Class.h>>>>>>>>>>
 #pragma once
class Class
{
public:
    int get_return(int a,int b,int (*compare)(int, int));
    static int Rxgmoral(int a,int b);
    void Fun();
};
<<<<<<<<<Class.Cpp>>>>>>>>
 #include "Stdafx.h"
#include "Class.h"
int Class::get_return(int a,int b,int(* compare)(int, int))
{
    return (compare(a,b));
}
int Class::Rxgmoral(int a, int b)
{
    return a+b;
}
void Class::Fun()
{
    int a;
    a=get_return(1,2,Class::Rxgmoral);
}
Last edited by WolfPack; Aug 3rd, 2006 at 7:48 am.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Aug 3rd, 2006
0

Re: Ask Function problem?thanks

thank you help
Reputation Points: 21
Solved Threads: 0
Newbie Poster
rxgmoral is offline Offline
14 posts
since Jul 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: home work help funcations and arry issues
Next Thread in C Forum Timeline: can't display the output! can somebody help me?!! PLS..





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC