Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Syntax Error When Using Explicitly Defaulted/Deleted Functions in Windows Phone 8 Project

DZone's Guide to

Syntax Error When Using Explicitly Defaulted/Deleted Functions in Windows Phone 8 Project

· Java Zone ·
Free Resource

Atomist automates your software deliver experience. It's how modern teams deliver modern software.

A few days ago a colleague of mine asked me to help with strange errors his C++ project kept throwing at him.

Since it was a C++ project we had more than 200 compilation errors but as the  C++ veterans that we are we’ve ignored most of them and scrolled up until we’ve found the patient zero of the issue – inside an header file that looked something like this:

class MyClassWP8
{
public:
    MyClassWP8();
    ~MyClassWP8();
 
    MyClassWP8& operator=(const MyClassWP8&) = delete;
    MyClassWP8(const MyClassWP8&) = delete;
    MyClassWP8(MyClassWP8&&) = delete;
};

Do you see the problem? – me neither.

If you’re not familiar with delete/default keyword (for a method), it’s a (relatively) new functionality added as part of C++ 11.

In C++11, defaulted and deleted functions give you explicit control over whether the special member functions are automatically generated. Deleted functions also give you simple language to prevent problematic type promotions from occurring in arguments to functions of all types—special member functions, as well as normal member functions and non-member functions—which would otherwise cause an unwanted function call.


From MSDN

Back in the days of VS2012 this functionality was not supported but since we were using VS2013 there was no apparent reason for it not to work.

We’ve verified that VS2013 support default/delete in desktop, WP8.1 and even Windows Phone Silverlght 8.1 applications. However when using the good old Windows Phone 8.0 application the code refused to compile.

After enabling verbose build  (Properties –> C/C++ –> General –> Suppress startup logo == No) I found the reason for the issue - while all of the projects used the newest C/C++ compiler.

image

Windows Phone 8.0 projects used and older compiler version that do not support some of C++11 features including explicitly deleted functions.
image

This is both logical and annoying at the same time - I guess that’s one more reason to upgrade to WP8.1.

Happy coding…

Get the open source Atomist Software Delivery Machine and start automating your delivery right there on your own laptop, today!

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}