C++ 无法从';初始值设定项列表';到用户控制器

C++ 无法从';初始值设定项列表';到用户控制器,c++,class,oop,compiler-errors,initializer-list,c++11,C++,Class,Oop,Compiler Errors,Initializer List,C++11,我有这门课: class UserController { private: Repo repo; Repo adoption; public: UserController(const Repo& r, const Repo& a) : repo(r), adoption(a) {} Dog get(int index) { return this->repo.get(index); }; }; 当我尝试创建UserController

我有这门课:

class UserController
{
private:
    Repo repo;
    Repo adoption;
public:
    UserController(const Repo& r, const Repo& a) : repo(r), adoption(a) {}

    Dog get(int index) { return this->repo.get(index); };
};
当我尝试创建UserController类型的对象时,如下所示:

UserController controller{ repo1, repo2 };
它告诉我错误:“错误C2440:‘初始化’:无法从‘初始值设定项列表’转换为‘UserController’”。为什么?

您需要编译此代码

下面我是在没有C++11支持的情况下编译的,并且使用(成功)

你需要编译这段代码

下面我是在没有C++11支持的情况下编译的,并且使用(成功)


是否在打开C++11的情况下编译?visual studio?看到了吗?你是在打开C++11的情况下编译的吗?visual studio?请看,我使用的是Visual Studio 2013,因此我不太确定是否使用C++11编译代码。它对一个论点有效,但我不知道为什么对两个论点无效…@Xyntell and?它是什么?我使用的是Visual Studio 2013,所以我不太确定我是否使用C++11编译代码。它对一个论点有效,但我不知道为什么对两个论点无效…@Xyntell and?那是什么?
Georgioss-MacBook-Pro:~ gsamaras$ g++ main.cpp 
main.cpp:14:20: error: no matching constructor for initialization of
      'UserController'
    UserController controller{ repo1, repo2 };
                   ^
main.cpp:2:7: note: candidate constructor (the implicit copy constructor) not
      viable: requires 1 argument, but 0 were provided
class UserController
      ^
main.cpp:8:5: note: candidate constructor not viable: requires 2 arguments, but
      0 were provided
    UserController(const Repo& r, const Repo& a) : repo(r), adoption(a) {}
    ^
main.cpp:14:30: error: expected ';' at end of declaration
    UserController controller{ repo1, repo2 };
                             ^
                             ;
2 errors generated.
Georgioss-MacBook-Pro:~ gsamaras$ g++ -std=c++0x main.cpp 
Georgioss-MacBook-Pro:~ gsamaras$