Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std;
- class PuntoQ1 {
- public:
- PuntoQ1() { }
- PuntoQ1(int x, int y, int sconto_fisso=0):
- x_{x >= 0 ? x : throw std::invalid_argument("x negativo")},
- y_{y >= 0 ? y : throw std::invalid_argument("y negativo")}
- { }
- //metodi getter / setter
- [[nodiscard]]auto x() const -> int {return x_;}
- auto set_x(int x) -> void {
- if (x<0)
- throw std::invalid_argument("x negativo");
- x_ = x;
- }
- private:
- int x_{};
- int y_{};
- };
- auto main() -> int
- {
- auto p1 = PuntoQ1{10, 34}; //OK
- std::println("{}", p1.x());
- }
Advertisement
Add Comment
Please, Sign In to add comment