#include <iostream>
using namespace std;
class Box
{
public:
Box(double l=2.0,double b=2.0,double h=2.0)
{
cout << "constructor called." << endl;
length = l;
breadth = b;
height = h;
}
double Volume()
{
return length * breadth*height;
}
int compare(Box box)
{
return this->Volume()>box.Volume();
}
Box* get_address() {
return this;
}
private:
double length;
double breadth;
double height;
};
int main()
{
Box box1(3.3,1.2,1.5);
Box box2(3.4, 1.4, 1.3);
Box* p = box1.get_address();
cout << p << endl;
p = box2.get_address();
cout << p << endl;
if (box1.compare(box2)) {
cout << "box2 is smaller than box2." << endl;
}
else {
cout << "box1 is smaller than box2." << endl;
}
}
#include"pch.h"
#include<iostream>
using namespace std;
class Box{
public:
Box() {}
~Box(){}
Box* getAddress() {
return this;
}
};
int main()
{
Box box1;
Box box2;
Box* box = box1.getAddress();
cout << box << endl;
box = box2.getAddress();
cout << box << endl;
return 0;
}