I am learning classes and I have a task just to practice for myself, and I need to modify this class:
class Object {
// modify this
};
template <typename Object>
void test(){
Object z, y(2);
if (z.x() == y.y()){
const Object x;
if (x.y() == Object::z())
return;
}
}
int main(int argc, char** argv) {
test<Object>();
return 0;
}
Nothing can be changed, only that class, so the code compiles without no errors. I am new to classes and it is hard for me to understand what exactly I have to put into that class so it compiles. I thought I need to make two constructors one with no no parameters and another with one parameter, then those x() and y() functions, but I am still getting errors. Well I mean I just did this:
class Object {
public:
Object() {
x1 = 2;
y1 = 2;
}
Object(int a) {
x1 = a;
y1 = a;
}
int x() {
return x1;
}
int y() {
return y1;
}
private:
int x1;
int y1;
};
template <typename Object>
void test() {
Object z, y(2);
if (z.x() == y.y()) {
const Object x;
if (x.y() == Object::z())
return;
}
}
int main(int argc, char** argv) {
test<Object>();
return 0;
}
I would be thankful if you would help me out on how this should look like..