is order to catch exceptions from constructors do i want to encase the constructing line and the entire following
string?
i mean, whatever is going to use the constructed thing
Well, I suppose so.
If the construction failed, I don't see how you can use the object at all.
will putting the main look in a try block hurt performance?
loop*
!rule 1
Make things work. Profile. Make things fast. In this order.
so i should put the main loop in a try block
and forget about performance
check on that later
You should profile the code, before and after, to check if the exception handling code has a significant or even measurable effect on performance.
how do i do that
valgrind
Use a profiler.
(Duh.)
EvanR, you should put a try block in main anyway. You don't want exceptions to leave main.
That leads to unspecified behaviour. Namely, whether destructors are called at all.
if the entire program crashes, everything is gone anyway right
and yes thats what im doing
EvanR, not necessarily
Crashing does not mean leaking an exception, btw
leaking an exception?
Letting main pass the exception without catching it
what happens
And it could be useful to not catch exceptions in main when developing. Easier to attach a debugger and examine the backtrace when the exception comes.
In release versions it's better to catch everything and let the program go down gracefully.
With an error message to the user.
ok but why cant i use the debugger in that situation
Because then you have to explicitly tell the debugger to break on an exception, and you can't break on "an exception that would fly all the way here". And if it's caught, you lose the site where it was thrown.
If it goes beyond main(), the debugger breaks and backtrace tells you where it was thrown.
The first one means that you would break on all (or many) exceptions, not just on the one that would make the program stop
i see
thats cool
ive never really used a debugger, you see
Hello. What's wrong here http://cpp.sourceforge.net/?show=39740 ? Is it a compiler bug? When I use first option I get proper object, but when I use template version I get garbage
You will love the idea that debuggers exist by the time your program reaches 3kloc
I use vc7
ironman, looking…
http://rafb.net/p/KfYYNA26.html = how is it possible for valgrind to output that loss stack ?
how can you lose memory during a constructor ?
let alone stand in operator new
ironman, is that the only getObject overload there is?
yes
I looked under debugger
I'm sure, I get garbage using template version
weird, right?
Weird.
so i have to throw away template function
For kicks, use a static_cast instead of that old-style-cast
And add some debug prints. Print the address that you get with the working code and the garbage code
oh, I always use old-style-cast.
in debugger: pointer p in template function has address 0×015281c8; in the second way it has 0×015281c8
the same address
when to use reinterpret_cast?
when you want to tell the compiler, hey, you might _think_ these bits are one type, but I know they are another
ironman, and the address of tex and t?
lol, in template it has the same address as p
And in the non-templated version?
0×012b1e98
So change the cast to a static_cast
so how should it be written with static_cast?
T* t = static_castT*(*p); ?
it works the same way
Yes, that way
No change?
nop
Wait, er, my head needs to be beaten
In the template version t has the same value as p?
yes
Show your code as it is now, with the debug prints
problem solved
i cleaned and rebuild
it works fine
woo!
visual studio didn't updated his database, when i modified that file
or something
is it possible to typedef a template ?
yes
but keep the template …
RenderOperationList;
no i wish to KEEP the tempalte
so basicly to provide a second name for the same class
oh, I don't know
class VerryLongClassName;
never tried
the other one is the preproccessor …
but that's dangerous
There are no templated typedefs but there's a trick
yes ?
Adrinael is a magician.
struct a { typedef VerryLongClassName b; };
is also aint