Dec 18, 2014

[C++14] Direct vs. Copy initialization

#include <iostream>
#include <initializer_list>
/*
 *  STD : 8.5 15-16 section
 */
using namespace std;

struct Fun
{

    explicit Fun() // Direct initialization default constructor , explicit
    {
    }
    explicit Fun(int) // Direct initialization with int , explicit
    {
    }

    Fun(initializer_list<int>) // Direct initialization , non-explicit
    {
    }

    Fun(const Fun&) // Copy initialization
    {
    }


};


int main()
{
    Fun f = {}; // calls default constructor
    Fun f = {1}; // calls initializer_list due to Fun(int) needs type conversion
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.