vendredi 4 octobre 2019

This pointer in c++

#include <iostream>

using namespace std;
class Box{
  public:
  Box(int x,int y, int z ):len(x),wid(y),high(z){}
  void set_vol(int ,int , int ); 
  void set_area(int ,int  ) ;
  int get_vol() ;
  int get_area();
  private:
  int len;
  int wid;
  int high;
};

    void Box::set_vol(int a,int b, int c) 
{
    this->len=a;
    this->wid=b;
    this->high=c;

}

    void Box::set_area(int a,int b) 
{

   this->len=a;
   this->wid=b;
}

    int Box::get_vol() {

    return this->len*wid*high;
}
    int Box:: get_area() {
    return this->len*wid;
}

int main()
{
    Box b1(3,4,5);
    cout<<"Box one:\n";
    cout<<"Volume = "<<this->get_vol()<<"\nArea = "<<this->get_area()<<endl;


    return 0;
}

I am not sure why this code is working. I get the following error. I am not sure why this code is working. I get the following error. I am not sure why this code is working. I get the following error. I am not sure why this code is working. I get the following error.

main.cpp:46:28: error: invalid use of ‘this’ in non-member function cout<<"Volume = "<get_vol()<<"\nArea = "<get_area()<

Aucun commentaire:

Enregistrer un commentaire