我有一个班级来管理笔,颜色集合和绘图: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:\users\md2i\desktop\current\branch\devel\sources\nrgraphicscomponents.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:\users\md2i\desktop\current\branch\devel\sources\nrgraphicscomponents.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自动完成时,它会向我显示所有重载的方法。
我不知道自己做错了什么。
感谢您的帮助
答案 0 :(得分:0)
好的,我解决了我的问题。我发布了答案,这可能有所帮助。
问题出在最后的参数上。 VS编译器无法将其转换为Gdiplus::DashStyle
(这是枚举),因此它会报告错误。但不是正确的错误。
所以我只需要将最后一个值转换为Gdiplus::DashStyle
并且它可以正常工作。
有关Gdiplus::DashStyle
的更多信息:http://msdn.microsoft.com/en-us/library/ms534104%28v=vs.85%29.aspx