c++ - How to test lvalue or rvalue in this case -


the code following:

struct a {    static int k;    int i; };   int a::k = 10;   a func() { a a; return a; } 

my question is, how can tell whether func().k or func().i lvalue or not? if both lvalues/rvalues, how can test them?

func().k = 0; // compile ok under g++-4.4 , g++-4.6 func().i = 1; // compile ok g++-4.4, g++-4.4 gives error:                //"using temporary lvalue [-fpermissive]" 

func().k lvalue , func().i xvalue.

you can see more details: rvalues , temporary objects in fcd

althrough, not difficult test whether lvalues or rvalues:

#include <iostream>  struct {     static int k;     int i; };  int a::k = 10;  func( ){ a; return a; }  void f (int & ) { std::cout << "int& " << std::endl; }  int main () {     func().k = 0;  //ok, because func().k r     f(func().k);     func().i = 1; //compile error: "using temporary lvalue"     f(func().i);  //compile error because func().i rvalue of type ‘int’     return 0; } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -