
mfc自定义函数指针
我在View中自定义了三个函数intdrawLine(CpointptOri,CpointptEnd),intdrawEllipse(CpointptOri,Cpoint...
我在View中自定义了三个函数 int drawLine(Cpoint ptOri,Cpoint ptEnd), int drawEllipse(Cpoint ptOri,Cpoint ptEnd)和 int Draw(int (*fun)(Cpoint ptOri,Cpoint ptEnd),Cpoint ptO,Cpoint ptE);
int DrawLIne(Cpoint ptOri,Cpoint ptEnd)
{
dc.moveto(ptOri);
dc.lineto(ptEnd);
return 0;
}
int Draw(int (*fun)(Cpoint ptOri,Cpoint ptEnd),Cpoint ptO,Cpoint ptE)
{
return (*fun)(ptO,ptE);
}
其中dc是我在view中定义CClient 成员变量
编译运行后提示 dc无权访问,后改用dc改为hdc型变量还是出错提示draw函数参数不足,请问我该如何修改draw函数
在view中构造函数中有,呆会我发原始代码上来请大侠们看看纠错
hdc dc=::getdc(m_hwnd);
void CtextdlgView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
Draw(DrawEllipse,ptOri,point);
CView::OnLButtonUp(nFlags, point);
}
nt CtextdlgView::Draw(int (*fun)(CPoint ,CPoint),CPoint ptOri,CPoint ptEnd)
{
return fun(ptOri,ptEnd);
}
error C3867: “CtextdlgView::DrawEllipse”: 函数调用缺少参数列表;请使用“&CtextdlgView::DrawEllipse”创建指向成员的指针
1>生成日志保存在“file://d:\vs2008study\textdlg\textdlg\Debug\BuildLog.htm”
1>textdlg - 1 个错误,0 个警告
请帮我修改下代码谢谢 展开
int DrawLIne(Cpoint ptOri,Cpoint ptEnd)
{
dc.moveto(ptOri);
dc.lineto(ptEnd);
return 0;
}
int Draw(int (*fun)(Cpoint ptOri,Cpoint ptEnd),Cpoint ptO,Cpoint ptE)
{
return (*fun)(ptO,ptE);
}
其中dc是我在view中定义CClient 成员变量
编译运行后提示 dc无权访问,后改用dc改为hdc型变量还是出错提示draw函数参数不足,请问我该如何修改draw函数
在view中构造函数中有,呆会我发原始代码上来请大侠们看看纠错
hdc dc=::getdc(m_hwnd);
void CtextdlgView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
Draw(DrawEllipse,ptOri,point);
CView::OnLButtonUp(nFlags, point);
}
nt CtextdlgView::Draw(int (*fun)(CPoint ,CPoint),CPoint ptOri,CPoint ptEnd)
{
return fun(ptOri,ptEnd);
}
error C3867: “CtextdlgView::DrawEllipse”: 函数调用缺少参数列表;请使用“&CtextdlgView::DrawEllipse”创建指向成员的指针
1>生成日志保存在“file://d:\vs2008study\textdlg\textdlg\Debug\BuildLog.htm”
1>textdlg - 1 个错误,0 个警告
请帮我修改下代码谢谢 展开
1个回答
展开全部
error C3867: “CtextdlgView::DrawEllipse”: 函数调用缺少参数列表.
这个错误的意思是: 你在调用这个函数时,所传递的参数个数不够。
你的这一句有误。
Draw(DrawEllipse,ptOri,point);
你的原意是:将“DrawEllipse”做为函数指针,以参数方式传给 Draw(...)方法。但由于写法不正确,导致了错误。
编译系统对你的代码理解是:将DrawEllipse()方法的结果做为Draw(...)调用的第一个参数。而它检查到DrawEllipse(。。。) 需要传入参数,但实际却没有,故提示:函数调用缺少参数列表。
要达到你的目的,你可以定义一个函数指针变量,用其指向相应的函数。再以这个函数指针变量做 为Draw(....)的参数,就OK 啦。
这个错误的意思是: 你在调用这个函数时,所传递的参数个数不够。
你的这一句有误。
Draw(DrawEllipse,ptOri,point);
你的原意是:将“DrawEllipse”做为函数指针,以参数方式传给 Draw(...)方法。但由于写法不正确,导致了错误。
编译系统对你的代码理解是:将DrawEllipse()方法的结果做为Draw(...)调用的第一个参数。而它检查到DrawEllipse(。。。) 需要传入参数,但实际却没有,故提示:函数调用缺少参数列表。
要达到你的目的,你可以定义一个函数指针变量,用其指向相应的函数。再以这个函数指针变量做 为Draw(....)的参数,就OK 啦。
追问
我明白了,谢谢,不过能帮吗写下代码吗,我没有见过类中函数指针用法
追答
我这里没有开发环境,不能帮你测试,你试试下面这样写行不行:
Draw( &DrawEllipse, ptOri, point);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询