Home > Back-end >  The map function pointer
The map function pointer

Time:09-26

# include & lt; iostream>
# include & lt; string>
# include & lt; Stack>
# include & lt; vector>
# include & lt; Map>

using namespace std;

Typedef int (* handler) (the);

The class CAL
{
Private:
Int num1.
Int num2;
Public:
CAL () : num1 (0), num2 (0) {}
CAL (int, int) b: num1 (a), num2 (b) {}
~ CAL () {}
Map Cal_;

Int add_ ()
{
Return (num1 + num2);
}
Int sub_ ()
{
Return (num1 - num2);
}
Int mul_ ()
{
Return (num1 * num2);
}
Int div_ ()
{
Return (num1/num2);
}

Void map_init ()
{
Cal_. Insert (make_pair (" + ", add_));
Cal_. Insert (make_pair (" - ", sub_));
Cal_. Insert (make_pair (" * ", mul_));
Cal_. Insert (make_pair ("/", div_));
}

};

Int main ()
{

return 0;
}
1> . \ sort. The CPP (41) : error C3867: "CAL: : add_" : the function call lack of parameter list; Please use "& amp; CAL: : add_ "create a pointer to member
1> . \ sort. The CPP (42) : error C3867: "CAL: : sub_" : the function call lack of parameter list; Please use "& amp; CAL: : sub_ "create a pointer to member
1> Sort. \. CPP (43) : error C3867: "CAL: : mul_" : function call lack of parameter list; Please use "& amp; CAL: : mul_ "create a pointer to member
1> . \ sort. The CPP (44) : error C3867: "CAL: : div_" : the function call lack of parameter list; Please use "& amp; CAL: : div_ "create a pointer to member

CodePudding user response:

Is unable to match the member function pointer and a function pointer

Should be changed to a member function pointer
 class CAL. 
Typedef int (CAL: : * handler) ();

The class CAL
{
Private:
Int num1.
Int num2;
Public:
CAL () : num1 (0), num2 (0) {}
CAL (int, int) b: num1 (a), num2 (b) {}
~ CAL () {}
Map Cal_;

Int add_ ()
{
Return (num1 + num2);
}
Int sub_ ()
{
Return (num1 - num2);
}
Int mul_ ()
{
Return (num1 * num2);
}
Int div_ ()
{
Return (num1/num2);
}

Void map_init ()
{
Cal_. Insert (make_pair (" + ", & amp; CAL: : add_));
Cal_. Insert (make_pair (" - ", & amp; CAL: : sub_));
Cal_. Insert (make_pair (" * ", & amp; CAL: : mul_));
Cal_. Insert (make_pair ("/", & amp; CAL: : div_));
}
};
  • Related