作业遇到问题,求教~~
作业叫创建一个C++类库不使用预编译头,输入代码如下:
Mandel.h
# using<System.Drawing.dll>
using namespace System::Drawing;
#using <mscorlib.dll>
public ref class Mandel
{
public:
int width, height; /* screen size */
long double midx, midy; /* image posn */
long double sizex, sizey; /* image size */
int Color(int ix, int iy);
};
Mandel.cpp
#include "Mandel.h"
int Mandel::Color(int ix, int iy)
{
unsigned iter = 0;
long double x, y, x2, y2, temp;
long double cy = midy + (2.0 * iy /height - 1.0) * sizey;
long double cx = midx + (2.0 * ix /width - 1.0) * sizex;
x = y = x2 = y2 = 0.0;
while( iter < 256 && ( x2 + y2 ) < 4.0) {
temp = x2 - y2 + cx;
y = 2 * x * y + cy;
x = temp;
x2 = x * x;
y2 = y * y;
iter++;
}
iter = 256 - iter;
int red = iter * 12 % 256;
int green = iter * 16 % 256;
int blue = iter * 5 % 256;
return Color::FromArgb(red, green, blue);
}
编译结果报错:“error C2440: “return”: 无法从“System::Drawing::Color”转换为“int” ”
我都是按照发的教程一步步做的但是还是有错
本人初学.net,望各位大侠指教!
谢谢
------解决方案--------------------Color结构没法直接转成int的.调用Color.ToArgb.
------解决方案--------------------
int Mandel::Color(int ix, int iy)
说明返回类型是int型,但你在函数中返回的是Color,而且Color不能隐式转换为int。
可以改为Color Mandel::Color(int ix, int iy)