-
February 15th, 2012, 11:16 AM
#1
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(), 0, 10);
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.
-
February 15th, 2012, 11:44 AM
#2
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.
-
February 15th, 2012, 12:13 PM
#3
Re: strtol is ambiguous error
Originally Posted by monarch_dodra
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(cin, input);
num = strtol(input.c_str(), 0, 10);
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++.
-
February 15th, 2012, 07:40 PM
#4
Re: strtol is ambiguous error
Originally Posted by JaySoyer
[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.
-
February 16th, 2012, 10:08 AM
#5
Re: strtol is ambiguous error
Originally Posted by Paul McKenzie
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|