코딩 및 기타

c++ 복습

정지홍 2023. 2. 28. 23:34

#include <iostream>
using namespace std;

class Rect;
bool equals(Rect r, Rect s);

class Rect {
    int w, h;
public:
    Rect(int w, int h) { this->w = w; this->h = h; };
    friend bool equals(Rect r, Rect s);
};

bool equals(Rect r, Rect s) {
    if (r.w == s.w && r.h == s.h)return true;
    else return false;
}

int main()
{
    Rect a(3, 4), b(4, 5);
    if (equals(a, b))cout << "equals" << endl;
    else cout << "not equals" << endl;
    return 0;
}


#include <iostream>
using namespace std;

class Rect;

class RectManager {
public:
bool equals(Rect r, Rect s);
};

class Rect {
int w, h;
public:
Rect(int w, int h) { this->w = w; this->h = h; };
friend bool RectManager::equals(Rect r, Rect s);
};

bool RectManager::equals(Rect r, Rect s) {
if (r.w == s.w && r.h == s.h)return true;
else return false;
}

int main() {
Rect a(3, 4), b(3, 4);
RectManager man;

if (man.equals(a, b))cout << "equals" << endl;
else cout << "not equals" << endl;

}