I'm using vectors in a class that creates different attributes for different types of units and I'm getting all kinds of errors like does not name a type, expected ',' or '....' before < token. If I use the include <vector> header file, the errors don't go away. If I combine the vector header file and add std to each vector, I get template argument 1 and 2 is invalid, string was not declared in this scope, suggestive alternative is std::string. If I use using namespace std, which I know I shouldn't, then I get undefined reference to window@86.
All of this is occurring in the SwordArmy header File.
#include <iostream>
#include "SwordArmy.h"
#include <vector>
usingnamespace std;
int main()
{
// Weloming Message
cout << "\t\tWelcome to my 2014 Combat Simulator. " << endl;
// Introduction.
cout << "\n\nFor a thousand years, the forces of evil have a laid seige";
cout << " on the kingdom of \nThebel. Their campaign have been relentless";
cout << " and ongoing throughout the ages.The victor of this";
cout << " battle will be remembered in history and be declared as";
cout << "King. The only question that remains is which side will";
cout << "you be fighting for? " << endl << endl;
string fightingSide; // Prompting the user to pick a side
cout << "\t\tPick a side!" << endl << endl;
cout << "1.) Sword Keepers " << " OR " << "2.) The Nocturnes ";
getline(cin, fightingSide, '\n');
// Checking for input validation.
while(fightingSide != "Sword Keepers" && fightingSide != "The Nocturnes" )
{
cerr << "\nYou've entered a faction that doesn't exist in the game. ";
getline(cin, fightingSide, '\n');
}
// A greeting from their faction.
if(fightingSide == "Sword Keepers")
{
cout << "\n(Human Voice)--Now let us fight in jolly cooperation!!! ";
}
elseif(fightingSide == "The Nocturnes")
{
cout << "\n(Grating Voice)-May you show the humans no mercy commander. ";
}
cout << endl;
// Advice before the battle begins.
cout << "\n\nBefore you can begin, you're going to need to assembly";
cout << " your army. Each unit has different strengths and weaknesses.";
cout << " Which means, you better pick wisely. ";
cout << endl;
vector<string> unitType; // The vector that contains every unit.
SwordArmy army;
army.setArmy(unitType);
cout << endl;
// If the user chose this faction.
if(fightingSide == "Sword Keepers")
{
// Display their units.
cout << "These are the units available for battle. " << endl << endl;
for(unsignedint i=0; i<unitType.size(); i++)
{
cout << i+1 << ".) " << unitType[i] << endl;
}
}
return 0; // Return zero if the program ran successful.
}
make your header self contained.
You are using std::string and std::vector in your header so you must #include <string> and #include <vector> in your header.
(also you need to qualify the namespace, like in std::vector)
> undefined reference to window@86.
perhaps you chose the wrong kind of project, try a console project instead
I did that but I still get errors like string was not declared in scope, template argument 1 and 2 is invalid, vector has not been declared and it suggests that I use std::string on line 10.
I'm using codeblocks and I chose console application(always have).
swordarmy.h line 10,12: usingnamespace std; hasn't been seen yet by the compiler, so as ne555 mentioned, you must qualify both vector and string by std::
I try to restart codeblocks(I've read that does the trick) and this is what I'm greeted with.
||=== Build: Debug in 1D Combat Simulator (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o:crt1.c|| multiple definition of `mainCRTStartup'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\crt2.o:crt1.c|| first defined here|
obj\Debug\main.o:crt1.c|| multiple definition of `WinMainCRTStartup'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\crt2.o:crt1.c|| first defined here|
obj\Debug\main.o:crt1.c|| multiple definition of `atexit'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\crt2.o:crt1.c|| first defined here|
obj\Debug\main.o:crt1.c|| multiple definition of `_onexit'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\crt2.o:crt1.c|| first defined here|
obj\Debug\main.o:cygming-crtbegin.c|| multiple definition of `__gcc_register_frame'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\crtbegin.o:cygming-crtbegin.c|| first defined here|
obj\Debug\main.o:cygming-crtbegin.c|| multiple definition of `__gcc_deregister_frame'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\crtbegin.o:cygming-crtbegin.c|| first defined here|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\crtbegin.o:cygming-crtbegin.c|| undefined reference to `_Jv_RegisterClasses'|
||=== Build failed: 13 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
So the winmax@16 went away, but now I get 13 new errors. AWESOME!!!!
I finally fixed this. Though I'll probably be back in case I have problems implementing vectors in this program since I haven't worked with vectors that much.
Now that those technical issues are fixed I can focus on setting each unit with different attribute points. If someone would like to work with me(because it does get boring doing this alone), message me.