Compiler errors

This is a discussion on Compiler errors within the C++ Programming forums, part of the General Programming Boards category; Hey, These seem like simple compiler errors but I have been unable to figure them out. Here are the errors ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    100

    Compiler errors

    Hey,

    These seem like simple compiler errors but I have been unable to figure them out. Here are the errors I am getting:

    Code:
    5 routeData.h expected init-declarator before '<' token 
    5 routeData.h expected `,' or `;' before '<' token 
    6 routeData.h expected init-declarator before '<' token 
    6 routeData.h expected `,' or `;' before '<' token 
    7 routeData.h expected init-declarator before '<' token 
    7 routeData.h expected `,' or `;' before '<' token 
    8 routeData.h expected init-declarator before '<' token 
    8 \routeData.h expected `,' or `;' before '<' token 
    20 routeData.h expected `;' before '(' token 
    22 routeData.h `iLst' does not name a type
    My code is:
    Code:
    #ifndef ROUTE
    #define ROUTE
    #include <set>
    #include <list>
    typedef set<int>		    iSet; // line 5
    typedef list<int> 		    iLst; // line 6
    typedef set<int>::iterator	iSetPtr; // line 7
    typedef list<int>::iterator	iLstPtr; // line 8
    
    using namespace std;
    
    class routeData
    {
        public:
    	
        	int readRouteData(istream & inSource);
        
        	int distance(int first, int second);
        
        	int distance(iLst route); // line 20
        
        	iLst bestRoute(iLst done, iSet left); // line 22
    };
    
    #endif

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You want to move your "using namespace std" to before where you start declaring your types from that namespace.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,765
    Better yet would be to remove the namespace directive altogether from the header file, since such practice is very bad form.

    Use the std:: prefix to all your standard namespace references.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Sep 2007
    Posts
    100
    Thanks!

    One new one (a warning):

    Code:
    int routeData::readRouteData(istream & inSource)
    {
        string temp;
        istringstream sstr;
        int ii;
        while(getline(inSource, temp))
        {
            // make sure string only contains digits and whitespace
            for(int aa = 0; aa < temp.length(); aa++) // line 20
            {
                if((!(isdigit(temp[aa]))) && (temp[aa] != ' '))
                {
                    cerr << "Bad input on line ";
                    exit(1);
                }
            }
        }
            
        return 0;
    }
    Code:
    20 routeData.cpp [Warning] comparison between signed and unsigned integer expressions
    "I don't fail - I succeed at finding things that don't work"
    Website Promotion Techniques @AbstractPromotion.com

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    Make aa a string::size_type, since that is the type returned by length().

  6. #6
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    or you can take the warning literally and make aa unsigned:
    Code:
    for(unsigned int aa = 0; aa < temp.length(); aa++)
    I am not sure if that is a good practice though.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Quote Originally Posted by cyberfish View Post
    or you can take the warning literally and make aa unsigned:
    Code:
    for(unsigned int aa = 0; aa < temp.length(); aa++)
    I am not sure if that is a good practice though.
    I'm guessing that would only suppress the warning if string::size_type is actually the same as unsigned int on the given platform (on a 64-bit box they might not be, for example). Also, the former is about the same number of characters to type anyway and is always the correct type.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by robatino View Post
    I'm guessing that would only suppress the warning if string::size_type is actually the same as unsigned int on the given platform (on a 64-bit box they might not be, for example). Also, the former is about the same number of characters to type anyway and is always the correct type.
    Not only bitness of the system. Let's say for example that the current architecture has a performance problem with unsigned numbers [say for example they need to be promoted to unsigned long long and then compared], there would be a good argument for someone implementing that particular compiler to change the size_type to signed.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,918
    Quote Originally Posted by Beowolf View Post
    Code:
    20 routeData.cpp [Warning] comparison between signed and unsigned integer expressions
    To clarify:
    This is because you're comparing a signed and unsigned integer (which is not possible AFAIK). The compiler will convert both types to either signed or unsigned, not sure which.
    To avoid this warning, only compare an unsigned integer to an unsigned and the same to signed. If you have one signed and one unsigned, cast one of them to unsigned/signed so you're comparing two of the same type.

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    > there would be a good argument for someone implementing that particular compiler to change the size_type to signed.

    I'm fairly sure that the Standard guarantees that not only std::size_t but any of the size_type's are always some unsigned integral type, so that's not an option.

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, and this is only a problem when one of the numbers MAY be signed - if you know for sure that both numbers [despite one of them being signed] can never be (validly) negative, then you can safely ignore the warning.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,918
    Quote Originally Posted by matsp View Post
    Yes, and this is only a problem when one of the numbers MAY be signed - if you know for sure that both numbers [despite one of them being signed] can never be (validly) negative, then you can safely ignore the warning.

    --
    Mats
    Or cast one to unsigned so the compiler shuts up

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    Or cast one to unsigned so the compiler shuts up
    Well, that is indeed a form of ignoring the warning. If one number is signed and the other unsigned and they both can be the full range of values, then there is no safe way to compare the values by casting. You will have to extend the size to the next level [e.g. going to (signed) long or long long] so that the unsigned number doesn't change sign.

    JUST adding a cast without understanding the full usage of the two numbers isn't safe!

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 10:13 AM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 11:50 AM
  3. bloodshed compiler errors
    By nerore in forum C++ Programming
    Replies: 5
    Last Post: 04-17-2004, 03:37 PM
  4. How to resolve linking errors?
    By m712 in forum C++ Programming
    Replies: 3
    Last Post: 11-03-2002, 10:17 PM
  5. Compiler errors
    By BellosX in forum C Programming
    Replies: 2
    Last Post: 09-21-2001, 04:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21