P
Pete C
As I understand it, any statement that *could* be interpreted as a
function declaration, must be. But what is the crucial difference
between these two snippets:
/***************************************/
#include <sstream>
using namespace std;
int main(int argc, char *argv[])
{
int retval;
istringstream stream(string(argv[1]));
stream >> retval; // error, line above was a fn declaration
return retval;
}
/***************************************/
#include <sstream>
using namespace std;
int main(int argc, char *argv[])
{
int retval;
const string str(argv[1]);
istringstream stream(str);
stream >> retval; // works OK
return retval;
}
/***************************************/
So, why did the version trying to use a temporary std::string fail?
Why does referencing a parameter (argv[1]) not make the statement
unambiguous?
And finally, an alternate version:
istringstream stream = istringstream(string(argv[1]));
fails for lack of an available copy constructor. I thought that with
this kind of initialisation, no copying takes place. What are the rules
here?
I'm using g++ 4.0.1, if it makes a difference.
Thanks...
function declaration, must be. But what is the crucial difference
between these two snippets:
/***************************************/
#include <sstream>
using namespace std;
int main(int argc, char *argv[])
{
int retval;
istringstream stream(string(argv[1]));
stream >> retval; // error, line above was a fn declaration
return retval;
}
/***************************************/
#include <sstream>
using namespace std;
int main(int argc, char *argv[])
{
int retval;
const string str(argv[1]);
istringstream stream(str);
stream >> retval; // works OK
return retval;
}
/***************************************/
So, why did the version trying to use a temporary std::string fail?
Why does referencing a parameter (argv[1]) not make the statement
unambiguous?
And finally, an alternate version:
istringstream stream = istringstream(string(argv[1]));
fails for lack of an available copy constructor. I thought that with
this kind of initialisation, no copying takes place. What are the rules
here?
I'm using g++ 4.0.1, if it makes a difference.
Thanks...