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

如何创建Gdiplus::GraphicsPath类型的std::vector?

关于Gdiplus::GraphicsPath存入std::vector的问题解答

问题场景

我想要创建一个Gdiplus::GraphicsPath类型的std::vector,代码如下:

std::vector<Gdiplus::GraphicsPath> test;

但当我尝试添加元素,执行以下代码时:

test.emplace_back(rndRectPathData.Points, rndRectPathData.Types, rndRectPathData.Count);

出现了以下错误:

Error   C2672   'std::construct_at': no matching overloaded function found  

Error   C2783   '_Ty *std::construct_at(_Ty *const ,_Types &&...) noexcept(<expr>)': could not deduce template argument for '<unnamed-symbol>'

Error   C2248   'Gdiplus::GraphicsPath::GraphicsPath': cannot access protected member declared in class 'Gdiplus::GraphicsPath'

请问这是否无法实现?原因是什么?

原因分析与结论

这确实无法直接实现,核心原因在于Gdiplus::GraphicsPath的类设计:

  • Gdiplus::GraphicsPath的构造函数被声明为protected,外部代码无法直接调用它创建对象,包括std::vector::emplace_back这种需要原地构造对象的场景,这也是错误C2248的直接来源。
  • GDI+框架下的这类图形对象,通常采用工厂模式设计,你需要通过类提供的静态创建方法(比如Create系列接口)来获取对象实例,而非直接构造。

正确的做法是改用指针容器存储,比如std::vector<std::unique_ptr<Gdiplus::GraphicsPath>>或者std::vector<Gdiplus::GraphicsPath*>,通过官方创建接口生成实例后存入容器。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 16:59:56