You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C++23技术疑问:默认实参的类型是否需要提前#include?

C++标准相关编译疑问

以下代码:

#include <memory>

struct A;

struct B {
    B(int){}
    B(std::unique_ptr<A> = nullptr);
};

int main(int, char**) {
    B b{1};
}

编译现象

  • 在MSVC v19.38搭配/std:c++latest编译选项时无法编译,报错信息:error C2027: use of undefined type 'A'
  • 在MSVC搭配/std:c++20编译选项时可正常编译
  • 在GCC搭配-std=c++23时也能编译通过
  • 若移除构造函数参数的默认值= nullptr,代码可正常编译

疑问

  1. C++标准对此场景有何规定?
  2. 编译此代码是否必须引入#include "A.h"?

内容的提问来源于stack exchange,提问作者Thibaud

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 09:19:58