Home > Net >  I can't get my code to print get volume fuction
I can't get my code to print get volume fuction

Time:10-10

#include <iostream>
using namespace std;
class Box
{
    public:
    double length;
    double breadth;
    double height;
    void getvolume();
    void setlength( double len)
    {
        length=len;
    }
    void setbreadth( double bre)
    {
        breadth=bre;
    }
    void setheight(double hei)
    {
        height=hei;
    }

};
void Box::getvolume()
    {
      double volume=0.0;
      volume= length*breadth*height;
      cout<<volume;
    }
int main()
{
    double volume1=0.0,volume2=0.0;
    Box box1;
    Box box2;
    //box 1 dimensions
    box1.setlength(12.0);
    box1.setbreadth(14.7);
    box1.setheight(19.5);
    //box 2 dimensions
    box2.setlength(3.4);
    box2.setbreadth(2.2);
    box2.setheight(23.4);

    cout<<"the volume of box 1 is";
    box1.getvolume;
    return 0;
}

in the most recent code which i've uploaded i receive error: statement cannot resolve address of overloaded function i have tried shifting get volume inside the class using double and void return type and calling the function with and without scope resolution operator and also tried calling the function as a value of another variable volume1.

CodePudding user response:

int main()
{
    double volume1=0.0,volume2=0.0;
    Box box1;
    Box box2;
    //box 1 dimensions
    box1.setlength(12.0);
    box1.setbreadth(14.7);
    box1.setheight(19.5);
    //box 2 dimensions
    box2.setlength(3.4);
    box2.setbreadth(2.2);
    box2.setheight(23.4);

    cout<<"the volume of box 1 is";
    box1.getvolume();
    return 0;
}

you just need to change box1.getvolume to box1.getvolume()

CodePudding user response:

You need to call the getvolume function using call() operator

box1.getvolume();
  •  Tags:  
  • c
  • Related