MFC工程,在CPlatformView.h声明了结构体和返回值为结构体的函数:
struct maxandindex
{
float maxvalue;
int index;
};struct maxandindex findmax(vector<float> x);然后在CPlatformView.cpp中实现函数
struct maxandindex CPlatformView::findmax(vector<float> x)
{
struct maxandindex m_i;
m_i.maxvalue=x[0];
for (int i=0;i<x.size();i++)
{
if (x[i+1]>x[i])
{
m_i.maxvalue=x[i+1];
m_i.index=i+1;
}
}
return m_i;
}E:\VC++Practice\Platform\通信仿真\V2\Platform\PlatformView.cpp(1739) : error C2556: 'struct maxandindex __thiscall CPlatformView::findmax(class std::vector<float,class std::allocator<float> >)' : overloaded function differs only by return type from
'struct CPlatformView::maxandindex __thiscall CPlatformView::findmax(class std::vector<float,class std::allocator<float> >)'
e:\vc++practice\platform\通信仿真\v2\platform\platformview.h(53) : see declaration of 'findmax'
E:\VC++Practice\Platform\通信仿真\V2\Platform\PlatformView.cpp(1739) : error C2371: 'findmax' : redefinition; different basic types
e:\vc++practice\platform\通信仿真\v2\platform\platformview.h(53) : see declaration of 'findmax'
Error executing cl.exe. 请问是怎么回事?谢谢!
struct maxandindex
{
float maxvalue;
int index;
};struct maxandindex findmax(vector<float> x);然后在CPlatformView.cpp中实现函数
struct maxandindex CPlatformView::findmax(vector<float> x)
{
struct maxandindex m_i;
m_i.maxvalue=x[0];
for (int i=0;i<x.size();i++)
{
if (x[i+1]>x[i])
{
m_i.maxvalue=x[i+1];
m_i.index=i+1;
}
}
return m_i;
}E:\VC++Practice\Platform\通信仿真\V2\Platform\PlatformView.cpp(1739) : error C2556: 'struct maxandindex __thiscall CPlatformView::findmax(class std::vector<float,class std::allocator<float> >)' : overloaded function differs only by return type from
'struct CPlatformView::maxandindex __thiscall CPlatformView::findmax(class std::vector<float,class std::allocator<float> >)'
e:\vc++practice\platform\通信仿真\v2\platform\platformview.h(53) : see declaration of 'findmax'
E:\VC++Practice\Platform\通信仿真\V2\Platform\PlatformView.cpp(1739) : error C2371: 'findmax' : redefinition; different basic types
e:\vc++practice\platform\通信仿真\v2\platform\platformview.h(53) : see declaration of 'findmax'
Error executing cl.exe. 请问是怎么回事?谢谢!
E:\VC++Practice\Platform\通信仿真\V2\Platform\PlatformView.cpp(1738) : error C2143: syntax error : missing ';' before 'tag::id' --->指向maxandindex CPlatformView::findmax(vector <float> x) E:\VC++Practice\Platform\通信仿真\V2\Platform\PlatformView.cpp(1738) : error C2501: 'maxandindex' : missing storage-class or type specifiers
E:\VC++Practice\Platform\通信仿真\V2\Platform\PlatformView.cpp(1738) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
按照二楼的建议改了函数名为myfindmax,错误与不改相同
{
float maxvalue;
int index;
} ;
CGDlg::maxandindex findmax(vector <float> x);CGDlg::maxandindex CGDlg::findmax(vector <float> x)
{
struct maxandindex m_i;
m_i.maxvalue=x[0];
for (int i=0;i <x.size();i++)
{
if (x[i+1]>x[i])
{
m_i.maxvalue=x[i+1];
m_i.index=i+1;
}
}
return m_i;
}