This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: error: no matching function for call to `Anton::Anton(Anton)`


> Hi Eric,
>
> Temporary objects are const.
> [...]
>
> HTH,
> --Eljay

Okay, but considering the following 7 is not exactly the same as a
instance of a class:

class A
{
public:
     A(){}
     A(A const &){}
  A& ref()
  { return *this; }
};

void f(A&){};

int main()
{
  int *i = &3;   // error: non-lvalue in unary `&'
  A   *p = &A(); // warning: taking address of temporary
  f(A().ref());  // works fine, even though ref is a non-const
memberfunction
  f(A());        // error: could not convert `A()' to `A&'
}

Btw p is a pointer to a non-const A, so is a temporary object const or not?

so why do the 2nd and 3rd line work and the 4th does not?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]