Skip to content

hw03 #35

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

hw03 #35

wants to merge 1 commit into from

Conversation

Sduby22
Copy link

@Sduby22 Sduby22 commented Feb 11, 2022

总结

  • 使用std::common_type<> 可以获得“共同类型”,原理是三元运算符的返回值类型为共同类型
  • 在定义变长模板参数时,如果只有一个变长模板参数,则会默认实例化出来一个变长参数为空的实例出来,此时会报错因为std::variant必须至少提供一个模板参数
    • 所以必须template <typename Arg, typename ... More>
  • 发现std::variantstd::vector相加时无法匹配到定义的模板加法运算符函数
    • 推测是此时模板参数无法推断,因为定义的模板函数第二个参数为std::variant<T1, T2>,此时加号右边是vector<double>
    • 如果手动定义指定模板类型,定义一个非模板函数的话,可以顺利通过编译,vector会被隐式转换为variant
    • 此处不知道如何解决,所以只能把vector静态类型转换为variant

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

Successfully merging this pull request may close these issues.

1 participant