In this code below, the foo function in the global scope tries to access Box private variables, which of course doesn't work. I need the foo function to work with one line of code in a place showing the code for the school assignment.
#include <iostream>
using namespace std;
class Box {
int x,y;
public:
Box(int xi,int yi) {x=xi;y=yi;}
};
bool foo(Box l,Box r) {return (l.x*l.y)>(r.x*r.y);}
int main(int argc, char* argv[]) {
Box b1(3,4),b2(1,2);
if (foo(b1,b2)) cout << "b1>b2\n";
return cin.get();
}
source
share