开发者

"deleting" copy ctor/assignment in C++11

In VS 2010 SP1, the following:

class Foo
{
public:
    Foo() { }
    Foo(Foo const&) = delete; // Line 365
    Foo& operator=(Foo const&) = delete; // Line 366
};

does not compile. It complains:

CPPConsole.cpp(365): error C2059: syntax error : ';'

CPPConsole.cpp(365): error C2238: unexpected token(s) preceding ';'

CPPConsole.cpp(366): error C2059: syntax error : ';'

CPPConsole.cpp(366): error C2238: unexpected token(s) preceding ';'

Is this not supported yet? The strange thing is, Intellisense seems to recognize this construct. It says "IntelliSense: function "Foo::operator=(const Foo &)" (declared a开发者_C百科t line 366) cannot be referenced -- it is a deleted function"

What am I missing?


VS 2010 has something of a dual personality. Specifically, it actually has two entirely separate compiler front ends.

When you compile the code, that's done with Microsoft's own compiler, which goes all the way back to MS C 3.0 for MS-DOS, released ~3 decades ago (in case you're wondering why it was 3.0, MS sold a re-labeled version of Lattice C before that).

Up until VS 2008, the parsing in the IDE was rather primitive compared to the compiler's, so it didn't parse a lot of more sophisticated C++ quite correctly. They decided that was unacceptable, and rather than try to upgrade the IDE's existing parser to match the compiler's, they licensed the EDG compiler front-end.

This gives more or less the opposite situation: the IDE's parser for Intellisense is now considerably closer to conforming than the one on the compiler, and recognizes a fair number of C++0x constructs that the compiler doesn't.

There's a little more to the story than just that though: the EDG compiler front-end supports a switch to make it act more like VC++, including emulating a fair number of VC++ bugs. Although I don't have data to confirm it, my assumption would be that Microsoft uses that capability. Since that's based on EDG taking the VC++ compiler, and emulating its bugs, it's probably a fair guess that (at least usually) EDG's VC++ emulation will run about a version behind VC++ itself. That gives the somewhat paradoxical situation where EDG (in normal use) is normally quite a bit ahead of VC++, but the version MS uses in the IDE is probably doing to be at least slightly behind most of the time.


It isn't implemented yet in VS2010.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜