Post by Jackstd::auto_ptr<BFThread> thread1;
thread1 = new BFThread(1, hEvent);
break;
////////////
I know I should have used BFThread*
But how do I take advantage of auto_ptr in this example?
I put a direct assignment inside the switch-case statement, but
it results in "Error 1 error C2360: initialization of 'thread1' is
skipped by 'case' label"
It was the original statement I coped from, and I wanted to keep it
intact. Anyway, I need to break it up into 2 statements inside wndproc.
What is the correct statement in this case?
Correct? Dunno, depends on your code. Anyhow, there are (at least) three
separate issues here:
1. You can not assign a raw pointer to an auto_ptr, you have to use reset().
2. The various case labels in a switch statement don't have a separate
scope, they all share access to their common scope. You must not skip a
call to a constructor (initialisation), which is what the compiler is
complaining about. Use a separate code block instead:
case ...:
{
....
}
break;
case ...:
3. All variables inside a function are local. If your windowproc is called,
it will each time create a new set of locals and on exit destroy them. This
might not be what you want.
Points 1 & 2 are completely independent of your current programming
problems. If you had actually taken the time to create a minimal test case,
as is customary on the Usenet, you could have asked more precise questions
and gotten more precise answers or even solved the problem yourself.
Uli
--
C++ FAQ: http://parashift.com/c++-faq-lite
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932