1
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
class M {
    vector<string> s;
    public:
    M(){
        s = {"abc", "abc", "abc", "abc", "abc"};
    }
};

int main(){
    return 0;
}

The code can be compiled in c9, but in vs2010, it can't be compiled successfully.why?

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
user2793559
  • 103
  • 1
  • 7

2 Answers2

3

MS VC++ 2010 does not support std::initializer_list as a parameter for member functions of standard containers.

Alan Stokes
  • 18,815
  • 3
  • 45
  • 64
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
1

You may follow this,

static const string arrStr[] = {"abc", "abc", "abc", "abc", "abc"};
vector<string> s(arrStr, arrStr + sizeof(arrStr)/sizeof(arrStr[0]));
Subhajit
  • 320
  • 1
  • 6