Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

[VS2013, C++] Initializer list in Ctor

$
0
0

Consider the following code:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    set<string> ssA{ { "a", "b" } };
    set<string> ssB( { "a", "b" } );

    for (auto s : ssA)
    {
        cout << s << endl;
    }

    for (auto s : ssB)
    {
        cout << s << endl;
    }    

    return 0;
}
Isn't ssA expected the same as ssB ? While, it throws a run-time error, 'cos the Ctor of ssA is taken as "set<string>(_Iter _First, _Iter _Last)", which will obviously try to cast stirng to _Iter .

Is it a feature or a bug or something else?


Viewing all articles
Browse latest Browse all 15302

Trending Articles



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