| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1683 人关注过本帖
标题:一个c++错误请大家指点
只看楼主 加入收藏
wghost
Rank: 2
等 级:论坛游民
帖 子:47
专家分:31
注 册:2009-6-6
结帖率:37.5%
收藏
已结贴  问题点数:20 回复次数:4 
一个c++错误请大家指点
#include<iostream>
using namespace std;
#include"student.h"
int main()
{   void max(student *p1);
    student stud[3]={student(1,56.8),student(2,89.3),student(3,78.3)},*p=stud;
    max(stud);
    return 0;
}
void max(student *p1)
{int i,j;
double t;
 
 for(i=0;i<2;i++)
    for(j=i+1;j<3;j++)
    if(*(p1+i)<*(p1+j))
     {t=p1[i];p1[i]=p1[j];p1[j]=t;}
}
其中红色部分提示一下错误:
D:\c++\ex3_h51\f.cpp(16) : error C2784: 'bool __cdecl std::operator <(const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &,const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &)' : could not deduce template argument for 'const class std::revers
e_iterator<_RI,_Ty,_Rt,_Pt,_D> &' from 'class student'
D:\c++\ex3_h51\f.cpp(16) : error C2784: 'bool __cdecl std::operator <(const struct std::pair<_T1,_T2> &,const struct std::pair<_T1,_T2> &)' : could not deduce template argument for 'const struct std::pair<_T1,_T2> &' from 'class student'
D:\c++\ex3_h51\f.cpp(16) : error C2676: binary '<' : 'class student' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\c++\ex3_h51\f.cpp(17) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class student' (or there is no acceptable conversion)
D:\c++\ex3_h51\f.cpp(17) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'double' (or there is no acceptable conversion)
Error executing cl.exe.
我是初学者,请指教!
搜索更多相关主题的帖子: return 
2009-10-27 12:53
qlc00
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:2
帖 子:157
专家分:540
注 册:2007-11-26
收藏
得分:3 
void max(student *p1)
你这里面的p1只是定义了一个类指针,它跟对象数组不一样,一直接使用它来进行数值的比较是不对的。void max(student *p1)如果是p1指向对象数组然后在使用指针的运算,那是正确的。但是你现在没有让指针指向任何东西,却让它来做运算这肯定是错的!

Anything is possible!
2009-10-27 13:11
AngzAngy
Rank: 1
等 级:新手上路
帖 子:8
专家分:3
注 册:2009-10-11
收藏
得分:3 
改正:void max(student *p1)
{int i,j;
 student *t;                 //////double t; 在此处改正
 
for(i=0;i<2;i++)
    for(j=i+1;j<3;j++)
    if(*(p1+i)<*(p1+j))
     {t=p1[i];p1[i]=p1[j];p1[j]=t;}
}

2009-10-27 13:44
newCpp
Rank: 5Rank: 5
来 自:火星
等 级:职业侠客
威 望:3
帖 子:256
专家分:375
注 册:2009-8-17
收藏
得分:3 
程序代码:
#include<iostream> 
using namespace std; 
struct student 
{ 
    int i; 
    int j; 
    int h; 
}; 
int main() 
{    
    void max(student *p1); 
    student stud[3]={1,56,8,2,89,6,3,78,3}; 
    max(stud); 
    return 0; 
} 
void max(student *p1) 
{ 
int i,j; 
int t; 
 
for(i=0;i<3;i++) 
{ 
cout<<p1->i<<" "<<p1->j<<" "<<p1->h<<endl; 
p1++; 
} 
} 
这玩意是是没有排序的,我也不清楚你要实现的啥功能,随便改了一下,自己参考参考吧!

编程语言视频教程在线播放学习
2009-10-27 22:48
东海一鱼
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:48
帖 子:757
专家分:4760
注 册:2009-8-10
收藏
得分:3 
编译器提示你的类型操作不匹配,也就是说在student这个类(结构)里,你没有重载'='、'>'、'<'这些操作符所以编译器无法处理这些代码。普通的操作符是对缺省变量类型操作的,无法对用户特定类型操作。除非你自己重载了这些操作符。

举世而誉之而不加劝,举世而非之而不加沮,定乎内外之分,辩乎荣辱之境,斯已矣。彼其于世未数数然也。
2009-10-27 23:01
快速回复:一个c++错误请大家指点
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012278 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved