>
> Hi,
>
> In the following 3 line program, I would expect that IsOpen will
return
> false since the TFile pointer doesn't point to anything. Instead, I
get a
> segmantation fault. This happens with both v3.04-02 and v3.03-09.
That is correct behavior for ANY C++ class. Your pointer points
arbitrary place in the memory (or ZERO) and this way you are getting an
arbitrary result (usually just a crash).
>
> #include <TFile.h>
> main()
> {
> TFile* f;
> f -> IsOpen();
> return 0;
> }
>
>
> I don't think I should get a segmentation violation here.
You must get it there.
> There are a few
> cases where f -> IsOpen() returning false would be very useful. I was
> wondering if this behavior could be implemented.
No it is not possible in C++.
What you probably need is:
#include <TFile.h>
main()
{
TFile* f = 0;
if (f) return f -> IsOpen();
return 0;
}
That will not crash.
Hope this helps, Valeri
Chhers,
-Kalen
> -----------------------------------------------------------------
> - Kalen Martens Ph:(416)-978-6632
-
> - Dept. of Physics -
> - University of Toronto, Toronto, Canada -
> -----------------------------------------------------------------
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:11 MET