gpt4 book ai didi

c++ - const char[] 默认函数参数

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:20:57 25 4
gpt4 key购买 nike

我定义了这样一个类型:

typedef char sType[256];

和一个带有默认参数的函数:

void foo(const sType param = NULL);

MinGW (g++ 4.8.0) 编译它没有错误。

相反,Visual Studio 2015 (Tools 14.0) 给出了以下错误:

error C2040: 'sType': 'int' differs in levels of indirection from 'char [256]'

我试图将 NULL 转换为 const char[],但这会导致:

error C2440: 'type cast': cannot convert from 'int' to 'const char []'

有什么提示吗?谢谢

最佳答案

不是将 NULL 转换为 const char[](或 sType),而是转换为 const char*。函数参数在 very declaration 中经历数组到指针的衰减.

关于c++ - const char[] 默认函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50287511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com