Hi, I have a constructor and a function called setValues. They're
both the same in how they act, but the function errors during
compiling. Could anyone give me any advice as to why this is
occurring?
Here is the code:
//beginning
#include <iostream>
#include <cstdlib>
using namespace std;
class area {
int *height, *width;
public:
area(int, int);
area();
~area();
void setValues(int, int);
int getArea() {
return (*height * *width);
}
};
area::area() {
width = new int;
height = new int;
}
area::area(int a, int b) {
width = new int;
height = new int;
*width = a;
*height = b;
}
area::~area () {
delete width;
delete height;
}
void area::setValues(int a, int b) {
*width = a;
*height = b;
}
int main(int argc, char *argv[]) {
int t1 = atoi(argv[1]);
int t2 = atoi(argv[2]);
area square(t1, t2);
area rect();
int t3 = atoi(argv[3]);
int t4 = atoi(argv[4]);
rect.setValues(t3,t4);
cout << "The area is: " << square.getArea() << endl;
return 0;
}
//end
Thanks,
Chad