0

Image 类是 BMP 类的子类。我正在尝试使用 BMP 类中的一些方法 TellHeight()、TellWidth() 等,以便在此方法中操作图像。但是,当我创建 BMP 并尝试对其调用函数时,编译时出现错误消息

未定义的符号:

BMP::BMP(),引用自:
Image::invertcolors()

这是方法 invertcolors():

void Image::invertcolors()
{
BMP img_invert;
img_invert.ReadFromFile("inverted.bmp");
//int height =img_invert.TellHeight();
//int width = img_invert.TellWidth();

//for(int i = 0; i<height; i++)
//{
//for(int j =0; j<width; j++)
//{
//RGBApixel* current = img_invert(j,i);
//current->Blue = 255 - (current->Blue);
//current->Green = 255 - (current->Green);
//current->Red = 255 - (current->Red);
//current->Alpha = 255 - (current->Alpha);
//}
//}
}
4

4 回答 4

2

未定义符号是链接时错误。链接二进制文件时,需要链接定义该函数的已编译代码。

如果 BMP 是外部库的一部分,则需要在链接行中添加如下内容:

 -L/path/to/lib -lbmp
于 2010-02-02T01:06:33.570 回答
1

BMP 没有无参数构造函数,您必须使用另一种方式来获取要使用的 BMP 实例。

于 2010-02-02T00:59:39.277 回答
1

您的 BMP 类没有默认构造函数。要么实现一个,要么让 Image 正确调用其父级的初始化程序。例如,

// this class does not have a default constructor:
class Parent 
{
public:
   Parent( int a ) { /* .. */ }
};


// so this one must call its parent's constructor with a parameter
class Child : public Parent
{
public:
   Child() : Parent(42) { /* .. */ } 
}
于 2010-02-02T01:00:03.977 回答
0

看起来更像是链接器错误。BMP 库未链接到

于 2010-02-02T01:04:36.987 回答