eGospodarka.pl
eGospodarka.pl poleca

eGospodarka.plGrupypl.comp.programmingZagwozdka - wyjątek w konstruktorze? › Re: Zagwozdka - wyjątek w konstruktorze?
  • Data: 2010-09-16 22:00:36
    Temat: Re: Zagwozdka - wyjątek w konstruktorze?
    Od: klops <k...@k...pl> szukaj wiadomości tego autora
    [ pokaż wszystkie nagłówki ]

    Sie troche pomyliłem... Powinno być tak:

    #include <iostream>
    #include <memory>
    using namespace std;
    char tab[100];
    struct Bar{
    Bar(){cout <<"Bar"<<endl;}
    ~Bar(){cout <<"~Bar"<<endl;}
    };
    class Foo{
    std::auto_ptr<Bar> b;
    public:
    Foo() : b(new Bar())
    {
    cout <<"Foo"<<endl;
    throw 1;
    }
    ~Foo()
    {
    cout <<"~Foo"<<endl;
    }
    static void * operator new (size_t size)
    {
    cout <<"new"<<endl;
    return (Foo*)tab;
    }
    static void operator delete (void *p, size_t size)
    {
    cout <<"delete"<<endl;
    }
    };

    main()
    {
    try{
    Foo *f=new Foo();
    }
    catch(...){
    cout <<"catch"<<endl;
    }
    }

Podziel się

Poleć ten post znajomemu poleć

Wydrukuj ten post drukuj

Najnowsze wątki z tej grupy


Najnowsze wątki

Szukaj w grupach

Eksperci egospodarka.pl

1 1 1

Wpisz nazwę miasta, dla którego chcesz znaleźć jednostkę ZUS.

Wzory dokumentów

Bezpłatne wzory dokumentów i formularzy.
Wyszukaj i pobierz za darmo: