Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std;
- class Test {
- public:
- //Test() {} dubbio: è forse incompleto?
- Test() = default; //nessun dubbio
- Test(int x) : x{x} {}
- private:
- int x{};
- };
- class PuntoQ1 {
- public:
- const int sconto_fisso;
- //costruttore di default (senza parametri) esplicito
- PuntoQ1(): sconto_fisso{0} { /* std::println("Chiamato il costruttore!");*/ }
- PuntoQ1(int x_val, int y_val, int sconto_fisso=0):
- x{x_val >= 0 ? x_val : throw std::invalid_argument("x negativo")},
- y{y_val >= 0 ? y_val : throw std::invalid_argument("y negativo")},
- sconto_fisso{sconto_fisso}
- {
- /* if (x_val < 0) throw std::invalid_argument("x negativo");
- if (y_val < 0) throw std::invalid_argument("y negativo");*/
- //x=x_val; //this->x = x
- //y=y_val;
- }
- private:
- int x;
- int y;
- };
- auto main() -> int
- {
- PuntoQ1 p1; //evitare
- PuntoQ1 p2 = PuntoQ1(); //evitare
- PuntoQ1 p3{}; //OK
- auto p4 = PuntoQ1{}; //OK
- auto p5 = PuntoQ1{3,5};
- auto p6 = PuntoQ1(3.8,5.1);
- try {
- auto p7 = PuntoQ1{ 3,-5};
- }
- catch (std::invalid_argument eccezione)
- {
- std::println("{}", eccezione.what());
- }
- Test n = Test{};
- }
Advertisement
Add Comment
Please, Sign In to add comment