'sword' does not name a type error

I've stripped my code down to it's absolute bare minimum and am still getting this error which I don't know how to resolve...

The code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <string>
using namespace std;

struct weaponData{
string name;
unsigned int atk;
unsigned int def;
unsigned int basePrice;
};
weaponData sword;
sword.atk = 60;
sword.basePrice = 70;
sword.def = 20;

int main(){
//stuff
}


The exact error I get is
|11|error: 'sword' does not name a type|

Thanks for any help :)
on what line?
http://www.codeproject.com/Questions/695278/Cplusplus-Error-this-declaration-has-no-storage-cl

You can't write code that would normally be in a "body" e.g. a function, outside of it.
Thanks, would these still be available globally, though? and @kbw line 11,12 and 13 all get the error.
Last edited on
NVM, answer is yes as main is obviously called first so if it's put in main then it'll be used throughout. Thanks very much :)
Topic archived. No new replies allowed.