怀疑自创建继承类的链接问题

Suspected linking issue with self created inherited class

本文关键字:链接 问题 继承 创建 怀疑      更新时间:2023-10-16

我有一些问题与类程序。我认为这是链接器的问题。这个程序没有语法问题,而且可以编译。问题是由程序中的一个类引起的。我试着从头开始重写这个,希望它是一个简单的语法错误,但没有工作。我还确保类文件位于包含目录列表中包含的目录中。

调用导致问题的FillerImage类的文件。

#include <cstdlib>
#include <sstream>
#include <iostream>

#include "globals.h"  //some global variables are included here
#include "pixel.h"  //includes the pixel class for storing individual pixels
#include "image.h"  //includes the image class we will be using.
#include "FillerImage.h"
using namespace std;
//declare your global variables here!
image* IM;
//load the filler images from the given folder into a vector of fillerImage.
bool loadFillerImagesFromFolder(string folder) 
{
    for (int i = FIRST_FILLER_NUMBER; i<= LAST_FILLER_NUMBER; i++){
        stringstream num;
        num << i;
        string filepath = folder + "/" + num.str() + FILLER_IMAGE_EXT;
        FillerImage* tmpFil = new FillerImage(filepath);
    }
    return false;
}

头文件

#ifndef FILLERIMAGE_H
#define FILLERIMAGE_H
#include "image.h"
#include "pixel.h"
using namespace std;
class FillerImage :image
{
    public:
        FillerImage(string filepath);
        bool setAverageColour();
    private:
        int timesUsed;
        pixel averageColour;
};

#endif

.

#include "FillerImage.h"
#include "pixel.h"
#include "image.h"
using namespace std;
FillerImage::FillerImage(string filepath):image(filepath){
    timesUsed = 0;
}
bool FillerImage::setAverageColour(){
    pixel** pix = getPixels();
    int height = getHeight();
    int width = getWidth();
    int averageRed, averageBlue, averageGreen = 0;
    for (int i = 0; i < height; i++){
        for (int j = 0; j< width; j++){
            averageRed += pix[i][j].red;
            averageBlue += pix[i][j].blue;
            averageGreen += pix[i][j].green;
        }
    }
    pixel tmppix;
    int pixels = width*height;
    tmppix.red = averageRed/pixels;
    tmppix.blue = averageBlue/pixels;
    tmppix.green = averageGreen/pixels;
    averageColour = tmppix;
}

FillerImage继承的图像类是由我的老师创建的,在上一个程序中工作得很好,所以我认为这不是问题。

Netbeans给出的错误是

g++ -headerpad_max_install_names - 0cs215pgm5。应用程序/内容/MacOS/cs215pgm5 mainForm。o形象。o cs215pgm5.o主要。o moc_mainForm。/Library/Frameworks -L/Library/Frameworks架构x86_64的未定义符号:"FillerImage::FillerImage(std::basic_string, std::allocator>)",引用自:loadFillerImagesFromFolder(std::basic_string, std::allocator>)在cs215pgm5。o ld:在体系结构x86_64中找不到符号退出状态make: * [cs215pgm5. 5]app/Contents/MacOS/cs215pgm5] Error 1

BUILD FAILED (exit value 2, total time: 131ms)

感谢您提供的帮助

似乎你还没有包括fillerimage.cpp在你的构建。如果您确实在使用Qt,那么它可能没有在Qt应用程序的. profile文件中列出source