Missing Type Specifier - Int Assumed in C++

pighead10 picture pighead10 · Mar 25, 2011 · Viewed 7.5k times · Source

These second line of these is throwing this error, but I'm not sure why.

std::vector<std::string> weapons(100);
weapons[3] = "Rusty dagger";

--

Here's my entire file:

//global variables
#ifndef _GLOBAL_
#define _GLOBAL_

#include <vector>
#include <iostream>
#include <string>

//prototypes
void NPCTalk(std::string const& speaker,std::vector<std::string> const& text);
void wait(double seconds);
void regionChange(int amount);
int getPositionInStringVector(std::vector<std::string> const& vec,std::string value);

//variables
std::vector<std::string> weapons(100);
weapons[3] = "Rusty dagger";

//defines
#define RegionChange 3

#endif //__GLOBAL__

Answer

Yakov Galka picture Yakov Galka · Mar 25, 2011
weapons[3] = "Rusty dagger";

This is a statement. You can't write statements in global scope. You must put it inside a function.