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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux