公有继承
问两个问题 小弟新手 问的幼稚请莫见怪程序如下
#include "stdafx.h"
#include <iostream>
#include "math.h"
using namespace std;
class CRect
{
float length;
protected:
float width;
float get_length() { return length;}
public:
float area(){return length * width;}
CRect(float l,float w)
{ length=l;width=w;}
};
class CParal:public CRect
{
float angle;
public:
float area() {return (float)(length * width * sin(angle));}//erro
CParal(float l,float w,float f):CRect(l,w)
{
angle=f;
}
};
float PI=3.14;
void main()
{
CParal paral(10,12,PI/6);
cout<<"The area of paral is: "<<paral.area()<<endl;
}
错误提示是这样的 error C2248: 'CRect::length' : cannot access private member declared in class 'CRect'
意思是否是length 是基类的的私有成员 不能直接访问 但我已经加了这句 float get_length() { return length;}
了啊 我开头这样写对不对#include "stdafx.h"
#include <iostream>
#include "math.h"
using namespace std;