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.
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?
Re: strtol is ambiguous error
Quote:
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++.
Re: strtol is ambiguous error
Quote:
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
Re: strtol is ambiguous error
Quote:
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.