Need assistance spotting error

When I tried compiling with the file shown below, the compiler gives this:

c:\codeblocks_v12\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\mingw32\bits\c++config.h|171|error: expected unqualified-id before 'namespace'|

Which points to a namespace std block that defines size_t and nullptr.
This caused a whole lot of other errors from size_t and nullptr not being members of the std namespace. I figured out that the problem somehow stems from the file below, but the compiler doesn't give me any specific line in any of my files. I really need help finding out what line in my code is causing this.

Note that the current code is incomplete.

I appreciate any help!

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
/** Clarification
   -Voter::str is a type alias for std::string
   -Voter::votes is a type alias for std::queue<unsigned>
**/
#include "Voter.h"

//Read-only
Voter::str Voter::name()const
    {return _name;}
Voter::str Voter::address()const
    {return _address;}
Gender_t Voter::gender()const
    {return _gender;}
bool Voter::alreadyvoted()const
    {return _already_voted;}
bool Voter::disabled()const
    {return _disabled;}
unsigned Voter::getPrecinct()const
    {return _precinct;}
Voter::votes Voter::getVotes()const
    {return _votes;}
PolParty_t Voter::politicalaffiliation()const
    {return _party;}
//Interactions
//void Voter::vote(const Ballot& ballot){
//}
//Constructor
Voter::Voter(
    str newname,
    //Follows format: 
    //   housenum streetname streettype, city, state(full)
    str newaddress,
    Gender_t newgender,
    bool newstatus,
    PolPart_t newparty
):
    _name(newname),
    _street(newaddress.substr(0, newaddress.find(','))),
    _city(newaddress.substr(
        newaddress.find(',') + 1,
        newaddress.find_last_of(',')
    )),
    _state(newaddress.substr(newaddress.find_last_of(',') + 1)),
    _gender(newgender),
    _already_voted(false),
    _disabled(newstatus),
    _party(newparty)
{}
Oh, and here's the header file if you need to see it:
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
#ifndef VOTER_H
#define VOTER_H

enum class PolParty_t{
    Democratic,
    Republican,
    Tea_Party,
    American_Independent,
    None
}
enum class Gender_t{
    Male,
    Female
}

#include <string>
#include <queue>

class Voter{
    public:
        using str = std::string;
        using votes = std::queue<unsigned>;
    //Read-only
        str name()const;
        str address()const;
        Gender_t gender()const;
        bool alreadyvoted()const;
        bool disabled()const;
        unsigned getPrecinct()const;
        const votes& getVotes()const;
        PolParty_t party()const;
    //Constructors and destructor
        Voter(
            str, // Name 
            str, // Address
            Gender_t,
            bool=false, // Disabled
            PolParty_t = PolParty_t::None
        );
        ~Voter()=default;
    private:
        str 
            _name,
            _street,
            _city,
            _state
        ;
        Gender_t _gender;
        bool _already_voted, _disabled;
        unsigned _precinct;
        votes _votes;
        PolParty_t _party;
};

#endif 
Last edited on
How about putting this outside the class declaration :

1
2
using std::string;
typedef std::queue<unsigned> votes;


Obviously you will have to have string name()const;

I think this might be better than a using alias, which in my mind is for abbreviating namespaces, as in :

namespace bg = boost::geometry;

Actually, is your use of using wrong in this case?

HTH
Your enum definitions must be terminated with a semi-colon. Because you #include after the incorrect enum definitions, the compiler believes the inclusion is part of your unfinished definition. A good reason to put your #includes before the code.

Holy crap, I can't believe it was as simple a mistake as that! I completely forgot that enum blocks need semi-colons; thanks Cire.

Also, thanks for your suggestion TheIdeasMan. I think I am using the using directive correctly (syntactically) because from what I read, using foo = bar; is the same as typedef bar foo; in C++11. Plus, I have used this style of scoping type aliases to the class definition in other projects, and it doesn't seem to cause any problems.
Topic archived. No new replies allowed.