| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2059 人关注过本帖
标题:连接错误。。--------------------Configuration: 派生 - Win32 Debug----- ...
取消只看楼主 加入收藏
fishviv
Rank: 1
等 级:新手上路
帖 子:45
专家分:9
注 册:2010-9-10
结帖率:90.91%
收藏
已结贴  问题点数:10 回复次数:5 
连接错误。。--------------------Configuration: 派生 - Win32 Debug--------------------
程序代码:
形状(一)
    编写C++程序完成以下功能:
声明一个基类Shape(形状),其中包含一个方法来计算面积;
从Shape派生两个类矩形和圆形;
从矩形派生正方形;
分别实现派生类构造函数、析构函数和其他方法;
创建派生类的对象,观察构造函数、析构函数调用次序;
不同对象计算面积。


#include<iostream>
using namespace std;
const double Pi=3.14;
class shape
{
   public:
      shape(){cout<<"shape constructor called"<<endl;}
      double Getarea(double x,double y){return area=x*y;}
      ~shape(){cout<<"shape destructor called"<<endl;}
   private:
      double area;
};
class rectangle:public shape
{
   public:
       rectangle();
       double rect(double X,double Y){return Getarea(X,Y);cout<<"rectangle constructor called"<<endl;}
        ~rectangle(){cout<<"rectangle destructor called"<<endl;}
   
};
class circle:public shape
{  public:
      circle();
      double cir_area(double r){cout<<"circle constructor called"<<endl;return  Pi*Getarea(r,r);}
      ~circle(){cout<<"circle destructor called"<<endl;}
};
class square:public rectangle
{
   public:
       square();
       double squa(double X){cout<<"square constructor called"<<endl;return Getarea(X,X);}
       ~square(){cout<<"aquare destructor called"<<endl;}
};
int main()
{   double l,w,r,x;
   
    cout<<"请输入长方形的长与宽"<<endl;
    cin>>l>>w;
    rectangle rec();
    cout<<"the area of rec is:"<<rec.rect(l,w)<<endl;
    cout<<"请输入圆的半径"<<endl;
    cin>>r;
    circle cir( );
    cout<<"the area of cir is:"<<cir.cir_area(r)<<endl;
    cout<<"请输入正方形的边长"<<endl;
    cin>>x;
    square squ( );
    cout<<"the area of squ is:"<<squ.squa(x)<<endl;
    return 0;
}


[ 本帖最后由 fishviv 于 2010-9-11 10:41 编辑 ]
搜索更多相关主题的帖子: 派生 Debug 
2010-09-11 09:45
fishviv
Rank: 1
等 级:新手上路
帖 子:45
专家分:9
注 册:2010-9-10
收藏
得分:0 
-------------------Configuration: 派生 - Win32 Debug--------------------
Compiling...
派生.cpp
C:\Users\zcy\Desktop\zz5z\派生.cpp(47) : error C2228: left of '.rect' must have class/struct/union type
C:\Users\zcy\Desktop\zz5z\派生.cpp(51) : error C2228: left of '.cir_area' must have class/struct/union type
C:\Users\zcy\Desktop\zz5z\派生.cpp(55) : error C2228: left of '.squa' must have class/struct/union type


[ 本帖最后由 fishviv 于 2010-9-11 10:43 编辑 ]
2010-09-11 09:46
fishviv
Rank: 1
等 级:新手上路
帖 子:45
专家分:9
注 册:2010-9-10
收藏
得分:0 
回复 3楼 hahayezhe
#include<iostream>
using namespace std;
const double Pi=3.14;
class shape
{
   public:
      shape(){cout<<"shape constructor called"<<endl;}
      double Getarea(double x,double y){return area=x*y;}
      ~shape(){cout<<"shape destructor called"<<endl;}
   private:
      double area;
};
class rectangle:public shape
{
   public:
       rectangle();
       double rect(double X,double Y){return Getarea(X,Y);cout<<"rectangle constructor called"<<endl;}
      
       ~rectangle(){cout<<"rectangle destructor called"<<endl;}
   
};
class circle:public shape
{  public:
      circle();
      double cir_area(double r){cout<<"circle constructor called"<<endl;return  Pi*Getarea(r,r);}
      ~circle(){cout<<"circle destructor called"<<endl;}
};
class square:public rectangle
{
   public:
       square();
       double squa(double X){cout<<"square constructor called"<<endl;return Getarea(X,X);}
       ~square(){cout<<"aquare destructor called"<<endl;}
};
int main()
{   double l,w,r,x;
   
    cout<<"请输入长方形的长与宽"<<endl;
    cin>>l>>w;
    rectangle rec();
    cout<<"the area of rec is:"<<rec.rect(l,w)<<endl;
    cout<<"请输入园的半径"<<endl;
    cin>>r;
    circle cir( );
    cout<<"the area of cir is:"<<cir.cir_area(r)<<endl;
    cout<<"请输入正方形的边长"<<endl;
    cin>>x;
    square squ( );
    cout<<"the area of squ is:"<<squ.squa(x)<<endl;
    return 0;
}
现在呢,为什么还说rect没有类啊?
2010-09-11 10:34
fishviv
Rank: 1
等 级:新手上路
帖 子:45
专家分:9
注 册:2010-9-10
收藏
得分:0 
形状(一)//这是原题目
    编写C++程序完成以下功能:
声明一个基类Shape(形状),其中包含一个方法来计算面积;
从Shape派生两个类矩形和圆形;
从矩形派生正方形;
分别实现派生类构造函数、析构函数和其他方法;
创建派生类的对象,观察构造函数、析构函数调用次序;
不同对象计算面积。
2010-09-11 10:36
fishviv
Rank: 1
等 级:新手上路
帖 子:45
专家分:9
注 册:2010-9-10
收藏
得分:0 
回复 7楼 hahayezhe
我看书上的默认构造函数就是  类名()  就好了啊,再说我加上{}之后,还是这个错误啊。
还有,什么是分给你啊?
2010-09-11 11:08
fishviv
Rank: 1
等 级:新手上路
帖 子:45
专家分:9
注 册:2010-9-10
收藏
得分:0 
好了,调好了,谢谢您的帮忙..麻烦再看看有什么不专业的地方。
#include<iostream>
using namespace std;
const double Pi=3.14;
class shape
{
   public:
      shape(){cout<<"shape constructor called"<<endl;}
      double Getarea(double x,double y){return area=x*y;}
      ~shape(){cout<<"shape destructor called"<<endl;}
   private:
      double area;
};
class rectangle:public shape
{
   public:
       rectangle(){cout<<"rectangle constructor called"<<endl;}
       double rect(double X,double Y){return Getarea(X,Y);}
       ~rectangle(){cout<<"rectangle destructor called"<<endl;}
   
};
class circle:public shape
{  public:
      circle(){cout<<"circle constructor called"<<endl;}
      double cir_area(double r){return  Pi*Getarea(r,r);}
      ~circle(){cout<<"circle destructor called"<<endl;}
};
class square:public rectangle
{
   public:
       square(){cout<<"square constructor called"<<endl;}
       double squa(double X){return Getarea(X,X);}
       ~square(){cout<<"aquare destructor called"<<endl;}
};
int main()
{   double l,w,r,x;
   
    cout<<"请输入长方形的长与宽"<<endl;
    cin>>l>>w;
    rectangle rec ;
    cout<<"the area of rec is:"<<rec.rect(l,w)<<endl;
    cout<<"请输入圆的半径"<<endl;
    cin>>r;
    circle cir ;
    cout<<"the area of cir is:"<<cir.cir_area(r)<<endl;
    cout<<"请输入正方形的边长"<<endl;
    cin>>x;
    square squ ;
    cout<<"the area of squ is:"<<squ.squa(x)<<endl;
    return 0;
}

2010-09-11 11:16
快速回复:连接错误。。--------------------Configuration: 派生 - Win32 Debug ...
数据加载中...
 
   



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

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