首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >函数类型-声明器-默认参数位置

函数类型-声明器-默认参数位置
EN

Stack Overflow用户
提问于 2016-08-31 08:44:08
回答 1查看 1.4K关注 0票数 2

我对函数声明的理解一直是,默认值参数在非默认值参数之后被声明为

但是,我刚刚注意到,我能够对一个打破此规则的函数声明进行类型化:

代码语言:javascript
复制
  typedef           // type of "int my_function ( int=1 , int )"
  int               // return type
  ( t_func_ptr )    // function type name
  ( int = 1         // arg0, default value - declared before non-default
  , int             // arg1
  ) ;

  /*
  // this wont compile, so why be able to typedef it?
  int my_bad_function ( int=1 , int )
  {
  } ;
  */

我很想知道为什么类型的人是可能的?

编辑:我用一系列编译器编译(我使用的是跨目标IDE),不确定底层编译器版本,需要检查,但目标是windows (mingw)、linux ubuntu、avr、arduino (atmega,need,uno)、raspberrypi、微芯片(chipkit)等。

  • i686-w64-mingw32-g++ (GCC) 4.8.2
  • g++ (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
  • avr-g++ (GCC) 4.8.1
  • arm-none-eabi-g++ (GNU Tools for ARM Embedded Processors) 4.8.3 20140228 (release) [ARM/embedded-4_8-branch revision 208322]
  • pic32-g++ (chipKIT) 4.5.1 chipKIT Compiler for PIC32 MCUs v1.31-20120614
  • arm-none-eabi-g++ (GNU Tools for ARM Embedded Processors) 4.7.4 20130913 (release) [ARM/embedded-4_7-branch revision 202601]
  • msp430-g++ (MSPGCC 20120406 (With patches: sf3540953 sf3559978))
  • 4.6.3 20120301 (mspgcc LTS 20120406 unpatched)
  • arm-linux-gnueabihf-g++ (crosstool-NG 1.17.0) 4.7.2
EN

回答 1

Stack Overflow用户

发布于 2016-09-02 15:37:24

默认参数只允许在函数声明和lambda-表达式的参数列表中使用(自C++14以来),并且在指向函数的指针的声明中、对函数的引用或在typedef声明(例如,参见参数)中不允许。

g++在声明接受默认函数参数的函数指针类型/非指针函数时出现了问题(请参阅bug 28262g++ v4.7.3g++ v4.8.1)。

这个bug是修正4.9.0版

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39244798

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档