Why is it impossible to exclude an incomplete type in the void?

Why does the following code give the following error?

Why must a type be filled in order to be different from void?

struct Incomplete;
class Class
{
    virtual void foo(Incomplete &incomplete)
    {
        (void) incomplete;
        throw std::logic_error("not implemented");
    }
};

Error:

error C2027: use of undefined type 'Incomplete'  
    see declaration of 'Incomplete'
+4
source share
2 answers

This is a change between C and C ++, where Microsoft previously applied C rules. As noted in a response to remyabel, this has been fixed.

In C, casting voidor simply using an expression as an instruction in itself (as in incomplete;) still includes the lvalue-to-rvalue conversion. C calls it a little differently, but it is the same conversion.

++ void lvalue-to-rvalue. , ++ lvalues, , lvalue-to-rval,

volatile int i;
i = 1;

, .

lvalue-to-rvalue , , , .

+6

, N4140:

§5.4/4 ,

[...]

- a static_cast (5.2.9),

[...]

.

§5.2.9/5 static_cast , . static_cast.

§5.2.9/6 cv void, (. 5). [...]

, Rextester, - VS2013, height4fun, - Microsoft, .

+3

All Articles