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

VS Code IntelliSense无法推导new表达式对应的模板函数参数

VS Code IntelliSense模板函数推导错误问题

错误信息

IntelliSense报出如下错误:

no instance of function template "some_template_function" matches the argument list C/C++(304)
template.cpp(10, 14): argument types are: ()

问题复现代码(包含<string>时报错)

#include <string>

template <class T> T* some_template_function(T *param)
{
    return param;
}

int main(int argc, char **argv)
{
    int *x = some_template_function(new int());      // IntelliSense报错
    int *y = some_template_function<int>(new int()); // 正常工作
}

场景1:移除<string>后IntelliSense恢复正常

template <class T> T* some_template_function(T *param)
{
    return param;
}

int main(int argc, char **argv)
{
    int *x = some_template_function(new int());      // 正常工作
    int *y = some_template_function<int>(new int()); // 正常工作
}

场景2:使用临时变量传递参数时(包含<string>也正常)

#include <string>

template <class T> T* some_template_function(T *param)
{
    return param;
}

int main(int argc, char **argv)
{
    int *temp = new int();
    int *x = some_template_function(temp);      // 正常工作
    int *y = some_template_function<int>(temp); // 正常工作
}

环境与已尝试操作

  • 系统:macOS 14.6
  • VS Code配置:搭配C/C++扩展v1.21.6
  • 触发时机:Xcode更新至16.0(16A242d)后出现该问题
  • 关键情况:所有代码实际编译均可正常通过,仅IntelliSense报错
  • 已尝试操作:调整VS Code中的intelliSenseMode和compilerPath参数,无法解决问题

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 10:04:55