标题:求高手帮忙、、、、
取消只看楼主
狼贲
Rank: 2
等 级:论坛游民
帖 子:17
专家分:13
注 册:2012-10-28
结帖率:100%
 问题点数:0 回复次数:1 
求高手帮忙、、、、
#include<stdio.h>
#include<iostream.h>
class base{
       public:
        virtual double getArea()=0;
};
class square:public base{
       public:
            square(double L){
               Long=L;
           }
           double getArea(){
              return Long*Long;
           }
       private:
          double Long;
};
class circle{
        public:
             circle(double r){
              R=r;
            }
            double getArea(){
              return 3.14*R*R;
            }
        private:
            double R;
};
int main(){
    double s1,s2;
    base *pd;
    square Sq(2.0);
    circle Cir(3.0);
    pd=&Sq;
    s1=pd->getArea();
    pd=&Cir;
    s2=pd->getArea();
   cout<<"s1="<<s1<<endl;
   cout<<"s2="<<s2<<endl;
return 0;
}

Compiling...
a.cpp
G:\BCheng\1\a.cpp(36) : error C2440: '=' : cannot convert from 'class circle *' to 'class base *'(问题就在这里,不知道怎么改)
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.

a.exe - 1 error(s), 0 warning(s)
搜索更多相关主题的帖子: double private include public return 
2012-11-13 19:16
狼贲
Rank: 2
等 级:论坛游民
帖 子:17
专家分:13
注 册:2012-10-28
得分:0 
我已经找到错误的原因了,谢谢。。。
2012-11-13 19:22



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-386937-1-1.html




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

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