Problem with placement of global variable access

I'm having a problem with placement of a statement accessing a global variable. The following code generates the compiler error: " 'swSerial' does not name a type "

#include <SoftwareSerial.h>

SoftwareSerial swSerial(4, 5);
swSerial.begin(9600);

void setup() {
}

void loop() {
}

When I move the begin statement inside the setup routine, the code compiles just fine:

#include <SoftwareSerial.h>

SoftwareSerial swSerial(4, 5);

void setup() {
  swSerial.begin(9600);
}

void loop() {
}

Can someone explain this to me? Thanks!

Code goes in functions & methods.

Its like relativity. Velocity means nothing without an observer. Code means northing without the framework of a function.

-jim lee