Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variant.hpp 中功能与书中不一致 #20

Open
taoyesheng opened this issue Mar 19, 2018 · 2 comments
Open

Variant.hpp 中功能与书中不一致 #20

taoyesheng opened this issue Mar 19, 2018 · 2 comments

Comments

@taoyesheng
Copy link

运行《深入应用C++11代码优化与工程级应用》。中139页的测试列子通过不了。您是否没有上传最新的代码

@qicosmos
Copy link
Owner

@taoyesheng 具体是哪个接口测试不通过?

@Phoenix500526
Copy link

@qicosmos 测试不不通过主要是因为在以下语句中:

    typedef Variant<int, double,  string, int> cv;
    cv v = 10;
    ...

得到的错误信息是:

In file included from test.cc:3:0:
Variant.h: In instantiation of ‘void Variant<Types>::destroy(const std::type_index&, void*) [with Types = {int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int}]’:
Variant.h:128:20:   required from ‘Variant<Types>::Variant(T&&) [with T = int; <template-parameter-2-2> = void; Types = {int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int}]’
test.cc:40:12:   required from here
Variant.h:190:25: error: no match for call to ‘(Variant<Types>::destroy(const std::type_index&, void*) [with Types = {int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int}]::<lambda(int&&, double&&, std::__cxx11::basic_string<char>&&, int&&)>) (int, int, int, int)’
         [](Types&&...){}((destroy0<Types>(index, buf), 0)...);
                         ^
Variant.h:190:25: note: candidate: void (*)(int&&, double&&, std::__cxx11::basic_string<char>&&, int&&) <conversion>
Variant.h:190:25: note:   candidate expects 5 arguments, 5 provided
Variant.h:190:22: note: candidate: Variant<Types>::destroy(const std::type_index&, void*)::<lambda(Types&& ...)> [with Types = {int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int}]
         [](Types&&...){}((destroy0<Types>(index, buf), 0)...);
                      ^
Variant.h:190:22: note:   no known conversion for argument 3 from ‘int’ to ‘std::__cxx11::basic_string<char>&&’
Variant.h: In instantiation of ‘void Variant<Types>::move(const std::type_index&, void*, void*) [with Types = {int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int}]’:
Variant.h:102:13:   required from ‘Variant<Types>::Variant(Variant<Types>&&) [with Types = {int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int}]’
test.cc:40:12:   required from here
Variant.h:202:25: error: no match for call to ‘(Variant<Types>::move(const std::type_index&, void*, void*) [with Types = {int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int}]::<lambda(int&&, double&&, std::__cxx11::basic_string<char>&&, int&&)>) (int, int, int, int)’
         [](Types&&...){}((move0<Types>(old_t, old_v, new_v), 0)...);
                         ^
Variant.h:202:25: note: candidate: void (*)(int&&, double&&, std::__cxx11::basic_string<char>&&, int&&) <conversion>
Variant.h:202:25: note:   candidate expects 5 arguments, 5 provided
Variant.h:202:22: note: candidate: Variant<Types>::move(const std::type_index&, void*, void*)::<lambda(Types&& ...)> [with Types = {int, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int}]
         [](Types&&...){}((move0<Types>(old_t, old_v, new_v), 0)...);
                      ^
Variant.h:202:22: note:   no known conversion for argument 3 from ‘int’ to ‘std::__cxx11::basic_string<char>&&’

如果将语句 typedef Variant<int, double, string, int> cv; 中的 string 删去,则代码可以编译通过,希望作者修一下这个 bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants