| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 648 人关注过本帖
标题:一道关于类的问题
只看楼主 加入收藏
枫xby
Rank: 5Rank: 5
等 级:职业侠客
威 望:8
帖 子:82
专家分:371
注 册:2014-10-19
结帖率:71.43%
收藏
已结贴  问题点数:10 回复次数:3 
一道关于类的问题
代码如下  求各位指导

#include<iostream>
using namespace std;
int main(){
    double f,g;
    double l,m,n;
   cout<<"请输入两个双精度浮点数:";
   cin>>f>>g;
   cout<<"请输入三个精度浮点数:";
   cin>>l>>m>>n;
   Compare compare1(f,g);
   Compare compare2(l,m,n);
   compare1.min();
   compare2.min_1();
   compare1.show();
   compare2.show_1();

   return 0;
   

}
class Compare
{  private:
     double t1;
     double t2;
     double x,y,z;
     double a,b;
  
   public:
      Compare(double ,double,double);
      Compare(double,double);
   
      void min();
      void min_1();
      void show();
      void show_1();

};
void Compare::min()
{   if(a>b)
       t1=b;
    else
       t1=b;
}
void Compare::min_1()
{
     double temp;
     if(x>y)
         temp=y;
     else
         temp=x;
     if(z>temp)
         t2=temp;
     else
         t2=z;

}
void Compare::show(){
    cout<<t1;
}
void Compare::show_1(){
    cout<<t2;
}
Compare::Compare(double f,double g)
{
    a=f;
    b=g;
}
Compare::Compare(double l,double m,double n)
{
    x=l;
    y=m;
    z=n;
}

错误显示为
D:\C++\test1\test1.cpp(10) : error C2065: 'Compare' : undeclared identifier
D:\C++\test1\test1.cpp(10) : error C2146: syntax error : missing ';' before identifier 'compare1'
D:\C++\test1\test1.cpp(10) : error C2065: 'compare1' : undeclared identifier
D:\C++\test1\test1.cpp(11) : error C2146: syntax error : missing ';' before identifier 'compare2'
D:\C++\test1\test1.cpp(11) : error C2065: 'compare2' : undeclared identifier
D:\C++\test1\test1.cpp(12) : error C2228: left of '.min' must have class/struct/union type
D:\C++\test1\test1.cpp(13) : error C2228: left of '.min_1' must have class/struct/union type
D:\C++\test1\test1.cpp(14) : error C2228: left of '.show' must have class/struct/union type
D:\C++\test1\test1.cpp(15) : error C2228: left of '.show_1' must have class/struct/union type
搜索更多相关主题的帖子: private include double return 
2015-05-02 20:14
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:5 
把类的声明写在main函数前面去
2015-05-02 21:38
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:2 
位置调一下,main函数下移到最后

剑栈风樯各苦辛,别时冰雪到时春
2015-05-02 21:42
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:3 
这儿还有个逻辑错误:
void Compare::min()
{   if(a>b)
       t1=b;
    else
       t1=b;
}
对t1赋值没有改动
2015-05-02 21:44
快速回复:一道关于类的问题
数据加载中...
 
   



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

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