Passing non-const references to rvalues in C++

前端 未结 7 989
长发绾君心
长发绾君心 2020-12-09 18:28

In the following line of code:

bootrec_reset(File(path, size, off), blksize);

Calling a function with prototype:

static void b         


        
7条回答
  •  执笔经年
    2020-12-09 19:06

    How can I force GCC to permit this code?

    If you own the definition of File then you can try playing tricks such as this one:

    class File /* ... */ {
    public:
      File* operator&() { return this; }
    /* ... */
    };
    /* ... */
    bootrec_reset(*&File(path, size, off), blksize);
    

    This compiles for me in c++98 mode.

    Does the upcoming C++0x standard change this in anyway, or is there something the new standard gives me that is more appropriate here, for example all that jibberish about rvalue references?

    Obviously this the way to go if at all possible.

提交回复
热议问题