使用重载方法时,Visual Studio错误C2664
Visual Studio error C2664 when using overloaded methods
我有一个类来管理钢笔,颜色集合和图纸:NRGraphics:
class NRGraphics
{
...
void newPen(std::string name, float epaisseur, Color couleur, DashStyle style);
void newPen(std::string name, float epaisseur, std::string colorName, DashStyle style);
...
}
这些是唯一具有该名称的方法。在某些函数中,我使用的最多的是第二个。
今天我正在写一个新类,我不得不使用第二个方法,所以我写的是:
void NRCell::draw(NRGraphics * drawer)
{
switch(backgroundStyle)
{
case Solid:
std::string colorName;
std::string borderPen;
std::string borderColorName = "pas de couleur";
try
{
colorName = drawer->findColor(color->Red(), color->Green(), color->Blue(), color->Alpha());
}
catch(std::exception e)
{
colorName = "R";
colorName += color->Red();
colorName += "G";
colorName += color->Green();
colorName += "B";
colorName += color->Blue();
colorName += "A";
colorName += color->Alpha();
drawer->newColor(colorName, color->Red(), color->Green(), color->Blue(), color->Alpha());
}
try
{
borderColorName = drawer->findColor(
borderColor->Red(),
borderColor->Green(),
borderColor->Blue(),
borderColor->Alpha());
borderPen = drawer->findPen(borderColorName, borderSize);
}
catch(std::exception e)
{
if(borderColorName == "pas de couleur")
{
borderColorName = "R";
borderColorName += borderColor->Red();
borderColorName += "G";
borderColorName += borderColor->Green();
borderColorName += "B";
borderColorName += borderColor->Blue();
borderColorName += "A";
borderColorName += borderColor->Alpha();
drawer->newColor(
borderColorName,
borderColor->Red(),
borderColor->Green(),
borderColor->Blue(),
borderColor->Alpha());
}
borderPen = "Pen_color_";
borderPen += borderColorName;
borderPen += "_size_";
borderPen += borderSize;
drawer->newPen(borderPen, (float)borderSize, borderColorName, 0);
}
drawer->DrawFilledSolidRectangle(
rect->getPt1()->X(), rect->getPt1()->Y(),
rect->getPt2()->X(), rect->getPt2()->Y(),
colorName,
borderPen,
borderSize
);
break;
/*case GradientHorizontal:
break;
case GradientVertical:
break;*/
}
}
下面是Visual Studio编译时输出的内容:
1>c:usersmd2idesktopcurrentbranchdevelsourcesnrgraphicscomponents.cpp(90): error C2664: 'void NRGraphics::newPen(std::string,float,Gdiplus::Color,Gdiplus::DashStyle)' : impossible de convertir le paramètre 3 de 'std::string' en 'Gdiplus::Color'
1> Aucun opérateur de conversion définie par l'utilisateur disponible qui puisse effectuer cette conversion, ou l'opérateur ne peut pas être appelé
错误信息的自动英文翻译:
1>c:usersmd2idesktopcurrentbranchdevelsourcesnrgraphicscomponents.cpp(90): error C2664: 'void NRGraphics::newPen(std::string,float,Gdiplus::Color,Gdiplus::DashStyle)' : can not convert parameter 3 from 'std::string' to 'Gdiplus::Color'
1> No conversion operator defined by the user available that can perform this conversion, or the operator can not be called
我有点困惑,因为当我使用Visual Studio自动完成时,它会显示我所有重载的方法。
我不知道我做错了什么。
谢谢你的帮助
好了,我的问题解决了。我把答案贴出来,可能会有帮助。
问题出在最后一个参数。VS编译器不能将其转换为Gdiplus::DashStyle
(这是一个枚举),所以它报告一个错误。但不是正确的错误。
所以我只需要将最后一个值转换为Gdiplus::DashStyle
,它就可以工作了。
Gdiplus::DashStyle
的更多信息:http://msdn.microsoft.com/en-us/library/ms534104%28v=vs.85%29.aspx
相关文章:
- Visual Studio 2015:Extern "C" 和 "export" 关键字
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 试图在visual studio上用C++创建一个桌面应用程序
- 如何在MS Visual Studio 2019中运行QT UI
- 如何使用Visual Studio 2017在C++中为参数化对象数组使用唯一指针
- Visual Studio Code - C++ Debugger 無法啟動
- Visual Studio 2019:插入多个C++风格的单行注释
- Visual Studio Code "undefined reference to `WinMain@16'"
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- Visual Studio中的函数声明和函数定义问题
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- Visual Studio mkl_link_tool.exe链接错误
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 不同的Visual Studio版本中缺少.dll
- 用Visual Studio在C++中嵌入Julia
- Visual Studio 2017循环自动向量化问题
- 有没有办法在远程设备上打开和编辑visual Studio 2017解决方案
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- Visual Studio在尝试读取resource.txt文件时崩溃
- Visual Studio 2017 不允许我创建 C++ 专用模板