Does not name a type error

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.

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include "SwordArmy.h"
#include <vector>

using namespace 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!!! ";
    }
    else if(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(unsigned int i=0; i<unitType.size(); i++)
        {
            cout << i+1 << ".) " << unitType[i] << endl;
        }

    }
    return 0; // Return zero if the program ran successful.
}


SwordArmy.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef SWORDARMY_H
#define SWORDARMY_H
#include <vector>
#include <string>

class SwordArmy
{
public:
    SwordArmy();
    std::vector<std::string> setArmy(std::vector<std::string> &);
private:
     // Different property Attributes for each unit
    std::vector<std::string> unitName;
    std::vector<int> damage;
    std::vector<int> speed;
    std::vector<int> mana; // Only for mages.
    std::vector<int> defense;
    std::vector<int> willPower;
    std::vector<float> hitChance;
};

#endif 


SwordArmy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <vector>
#include "SwordArmy.h"

using namespace std;

SwordArmy::SwordArmy()
{

}

vector<string> SwordArmy::setArmy(vector<string> &name)
{
   // The name of each unit
   name.push_back("Arcane Mage");
   name.push_back("Templar");
   name.push_back("Rogue");
   name.push_back("Berseker Knight");
   name.push_back("Pikeman");
   name.push_back("Archer");
   name.push_back("Wyvern Rider");
   name.push_back("Girffions");
   name.push_back("Infantry");
   name.push_back("Defenders");

   unitName = name;

   return unitName;
}
Last edited on
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: using namespace std; hasn't been seen yet by the compiler, so as ne555 mentioned, you must qualify both vector and string by std::

1
2
3
  void setName(std::vector<std::string> &);
...
   std::vector<std::string> unitName;


Yes, then we come to problem of having an undefined reference to WinMain@16.
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!!!!
Last edited on
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.
Last edited on
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.
Topic archived. No new replies allowed.