错误的自动扣除 c++14
Wrong auto deduction c++14
我对"auto"返回类型函数有一种奇怪的行为。有人知道为什么第二个函数调用返回 int 而不是双精度吗?
编译器版本: g++ (Ubuntu 5.4.0-6ubuntu1~16.04.10( 5.4.0 20160609
#include <string>
#include <iostream>
double operator+(const int& a,const std::string& b){
return 3.4;
}
auto f(){
return 3.4;
}
auto sum(auto a, auto b){
return a + b;
}
int main(){
std::cout<< sum(1.0, std::string("hello")) <<std::endl;
std::cout<< sum(1, std::string("hello")) <<std::endl;
std::cout<< f() << std::endl;
}
//3.4
//3
//3.4
首先,自动函数参数不是标准C++。这是一个gcc扩展,期待标准委员会的一些工作。有一次有人谈论允许这种语法与概念的引入。我不知道情况是否仍然如此。
至于奇怪的行为,它看起来只是一个编译器错误,修复在gcc 5.5.0和gcc 6.1.0之间
相关文章:
- 错误的自动扣除 c++14
- 编译器现在遵循C++14标准,我的项目不再编译神秘的SFML错误
- C++14 遇到奇怪的"use of deleted function"错误
- 在 Slackware 14.2 64 位上使用 ACE 库编译错误
- 由于 2D 数组声明,C++ 14 中的运行时错误
- G++ (C++14) 链接器错误,用于处理 C++03 代码
- C++14 类函数错误:"Object has no attribute 'value'"
- 新的 C++14 位分隔符处"Bad Character" Eclipse Oxygen 错误
- VS 中的 C++ 17 会导致 C++14 中不存在的变量(重新)评估错误
- 在 Ubuntu 14.04 上构建 AWS c++ 配置库时出现"return type is incomplete"错误
- C++14 unique_ptr并使用已删除的函数'std::unique-ptr' unique_ptr错误
- 我正在尝试在Ubuntu 14上安装libgtk2.0-dev,但出现了一些错误
- 使用GCC v4.8在Ubuntu 14.04上定义C 11中元组向量时的编译错误
- 在Ubuntu 14.04启动我的应用程序时,非法说明(核心转储)错误,如何查看转储
- g 编译选项,带有-STD = C 14编译错误显示Werror = C 11 -Compat
- Visual Studio 14.0使用CSTDINT和STDINT.H给出编译错误
- Visual Studio 14.0 和 Windows 工具包中的错误包括文件夹
- 在 Ubuntu 14.04 下将错误与“libopencv_highgui.so”链接,与“libtiff.so.5”
- LNK2019:OPNET 14.5A 中未解决的外部符号错误
- 简短版本:错误 14 错误 C2660:'Player::addSpell':函数不接受 1 个参数