Quantcast
Channel: Intel® Software - Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 2797

Uniform Initialization and default constructor arguments in C++11

$
0
0

Hi ! First of all, big Kudos to Intel for supporting Educational Community !!!

I wrote small program to try out new feature in C+11 - Uniform Initialization. However, getting a lot of errors and one incorrect result.
(Basically, I am following http://www.informit.com/articles/article.aspx?p=1852519)
Using Visual Studio 2012(latest) with Intel C++ Compiler 13(latest). C++0x support enabled.

#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

class C {
public:

    C(int a = 1, int b = 2) : n{0,1,2,3,4}, a_{a}, b_{b} {};
    int n[5];
    int a_,b_;

};

int main()
{
    C c = C{}; // OK
    C *p = new C; // OK
    //C *p2 = new C{}; // Does not compile

    cout << c.a_ << "  "<< c.b_ << endl; // Getting "0 0" instead of  "1 2"

    int var{0}; // OK
    string s{"hello"}; // OK
    string s2{s}; // OK copy constructor
    //vector<string> vs{"alpha", "betta", "gamma"}; // Does not compile
    //double *pd= new double [3] {0.5, 1.2, 12.99}; // Does not compile

    //int n{}; // Does not compile
    //int *p{}; // Does not compile
    //char s[12]{}; // Does not compile
    //string s{}; // Does not compile
    //char *p=new char [5]{};
    return 0;
}

Thanks !


Viewing all articles
Browse latest Browse all 2797

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>