dimanche 5 avril 2020

Having trouble assigning border width from function call from derived class

this is where i defined the window class and the derived class i just started working with inheritance and im trying to work through this example from class any reference to where i can learn inheritance easier would be helpful as well as help with this particual question! Trying to work through it guys

//Window class
class Window{
    private:
        int width;

    public:
int getwidth(){
int width;
cin>>width;
return width;

};


};

the subclass of window

//subclass
class WindowWithBorder:public Window{
    private:
        int BorderWidth;
    public:
//constructor that accepts an integer parameter which is used to initialize the instance variable
WindowWithBorder(int);
int GetUseableWidth(int x,int y){


    //return width of window minus the width of the border
    int UseableWidth;
    UseableWidth=x-y;
    return UseableWidth;



};
};



int main(){
//1.








//2.
Window obj1;



int useablewidth;
int width,borderwidth;
cout<<"Enter a width: ";
width=obj1.getwidth();

this is where im having a problem.........

borderwidth=obj1.WindowWithBorder(4);
//useablewidth=GetUseableWidth(width,BorderWidth);
//cout<<endl;
//cout<<"The useable width is: "<<useablewidth;




return 0;
};

Aucun commentaire:

Enregistrer un commentaire