Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Avem o clasa Punct in care nu avem voie sa avem valori negative!
- // Prin utilizarea pointerilor putem face un bypass la validare.
- #include <iostream>
- using namespace std;
- class Punct {
- private:
- int X, Y;
- public:
- Punct(int X, int Y)
- {
- if (X >= 0 && Y >= 0)
- {
- this->X = X;
- this->Y = Y;
- }
- else throw "Nu poti pune numere negative";
- }
- int getX()
- {
- return X;
- }
- int getY()
- {
- return Y;
- }
- };
- int main()
- {
- Punct P1(10, 20); // merge!
- Punct P2(-5, 10); // crapa!
- struct Point { int X, Y; };
- Point str_P = { -5, 10 };
- Punct *pct = (Punct*) &str_P;
- cout << pct->getX() << " " << pct->getY() << endl; // Nu mai crapa! Acum putem avea valori negative
- cin.get();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement