CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2012
    Location
    United States
    Posts
    12

    Question strtol is ambiguous error

    Anyone know how to fix this semantic error or why its screaming at me?

    PHP Code:
    long int num strtol(input.c_str(), 010); 
    Causes a semantic error: 'strtol' is ambiguous.
    Not sure if its more an IDE thing, but I'm using Eclipse CDT and the g++ compiler for Mac OS.

  2. #2
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: strtol is ambiguous error

    This piece of code works fine for me, as well as a few other variants I could think of.

    Code:
    #include <string>
    #include <cstdlib>
    
    int main()
    {
      std::string input;
      long int num1 = std::strtol(input.c_str(), 0, 10);
      long int num2 = strtol(input.c_str(), 0, 10);
    }
    Could you post a full example that recreates this error, as well as the complete error message?

    EDIT: You say "Not sure if this is an IDE thing", are you getting a compile error, or is this a code completion/lookup problem?
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  3. #3
    Join Date
    Jan 2012
    Location
    United States
    Posts
    12

    Re: strtol is ambiguous error

    Quote Originally Posted by monarch_dodra View Post
    Could you post a full example that recreates this error, as well as the complete error message?

    EDIT: You say "Not sure if this is an IDE thing", are you getting a compile error, or is this a code completion/lookup problem?
    PHP Code:
    void RemovePhrase()
    {
        
    string input;
        
    long int num;

        
    cout << "Enter phrase ID number to delete (0 cancel): ";
        
    getline(cininput);

        
    num strtol(input.c_str(), 010);

        if (
    num 0)
        {
            if (!
    mFavorites->RemovePhrase(num)) cout << "Failed to delete " << num << endl;
        }
        
    cout << endl;

    That's the function it happens in. Good point about compile error. Compiling through command line doesn't cause an issue. Also, it doesn't show up as an error in Eclipse's build console and I can run my program fine. Just appears overlaid on my IDE and in the problems list. Which I guess that means it's Ecplise that doesn't like it and not g++.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: strtol is ambiguous error

    Quote Originally Posted by JaySoyer View Post
    [php]void RemovePhrase()
    {
    You did not post a full example. A full example means that we can copy and paste the code you have, and without changing anything, compile and see any issues.

    What are the exact header files you're using for this module? Compiling successfully and/or without warnings requires the correct set of headers.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; February 15th, 2012 at 07:44 PM.

  5. #5
    Join Date
    Jan 2012
    Location
    United States
    Posts
    12

    Re: strtol is ambiguous error

    Quote Originally Posted by Paul McKenzie View Post
    You did not post a full example. A full example means that we can copy and paste the code you have, and without changing anything, compile and see any issues.

    What are the exact header files you're using for this module? Compiling successfully and/or without warnings requires the correct set of headers.
    Unfortunately I can't give the full code for multiple reasons. However monarch sent me on the right track. Fixed the problem. Eclipse offered two ways to link with header's outside the project directory. Either by manually entering the -I command line argument or by going through some GUI project reference thing. While both ways allowed me to compile and run the program, the latter caused the semantic errors to show up. For as much as I love Eclipse, it does have its annoyances.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured