S
soft_guy
I have an issue I would like to understand. I have a class which takes
arguments in its constructor which are references to objects. I'm
going to use QString as an example because that's the class that I'm
really having this issue with, but I suspect it could just as easily
many other types.
Example:
class Person
{
public:
Person(const QString & fn, const QString & ln) : firstName(fn),
lastName(ln) {}
private:
QString firstName;
QString lastName;
};
Let's say there are functions like this which can generate data:
QString generateFirstName();
QString generateLastName();
Then I want to create an instance of my class:
Person somedude(generateFirstName(), generateLastName());
This results in a compiler error that says "no matching function call
for Person:erson(QString, QString). Candidates are
Person:erson(QString &, QString &)". (I'm seeing this error in GCC
4.0.1.)
I can get the error to go away by doing this:
QString fn = generateFirstName();
QString ln = generateLastName();
Person somedude(fn, ln);
I'd like to understand why I'm seeing this error and what it means. I
know at a basic level that it is because I'm trying to pass the
results of a function call rather than an actual variable, but why are
these different?
Thanks.
Brant Sears
arguments in its constructor which are references to objects. I'm
going to use QString as an example because that's the class that I'm
really having this issue with, but I suspect it could just as easily
many other types.
Example:
class Person
{
public:
Person(const QString & fn, const QString & ln) : firstName(fn),
lastName(ln) {}
private:
QString firstName;
QString lastName;
};
Let's say there are functions like this which can generate data:
QString generateFirstName();
QString generateLastName();
Then I want to create an instance of my class:
Person somedude(generateFirstName(), generateLastName());
This results in a compiler error that says "no matching function call
for Person:erson(QString, QString). Candidates are
Person:erson(QString &, QString &)". (I'm seeing this error in GCC
4.0.1.)
I can get the error to go away by doing this:
QString fn = generateFirstName();
QString ln = generateLastName();
Person somedude(fn, ln);
I'd like to understand why I'm seeing this error and what it means. I
know at a basic level that it is because I'm trying to pass the
results of a function call rather than an actual variable, but why are
these different?
Thanks.
Brant Sears