I have some code that is like this:

Code:
(input is a stream &)

[...]
stream *uncompStream;

if (compressed == false)
{
    uncompStream = &input;
}
else
{
    uncompStream = new uncompress_stream(&input);
}
[...]
Is there any way to write this code without dynamically allocating the uncompress_stream class?
I can't find any way to allocate the uncompress_stream in the stack without it being destroyed in the "}".

The only "automatic" solution that I've found is to use a smart pointer (assigned to NULL initially), and use it if it I need an uncompress_stream. However, that looks a bit bad.