C++ 怀疑与自建继承类存在链接问题
我对上课的程序有一些问题。我认为这是链接器的问题。这个程序没有给我任何语法问题和编译。这些问题源于程序中的一个类。我曾尝试从头开始重写它,希望它是一个简单的语法错误,但没有成功。我还确保类文件位于包含目录列表中包含的目录中 调用导致问题的FillerImage类的文件C++ 怀疑与自建继承类存在链接问题,c++,C++,我对上课的程序有一些问题。我认为这是链接器的问题。这个程序没有给我任何语法问题和编译。这些问题源于程序中的一个类。我曾尝试从头开始重写它,希望它是一个简单的语法错误,但没有成功。我还确保类文件位于包含目录列表中包含的目录中 调用导致问题的FillerImage类的文件 #include <cstdlib> #include <sstream> #include <iostream> #include "globals.h" //some global v
#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;
}
#包括“FillerImage.h”
#包括“像素.h”
#包括“image.h”
使用名称空间std;
FillerImage::FillerImage(字符串文件路径):图像(文件路径){
所用时间=0;
}
bool FillerImage::setAverageColor(){
像素**pix=getPixels();
int height=getHeight();
int width=getWidth();
int averaged,averageBlue,averageGreen=0;
对于(int i=0;i
FillerImage继承的image类是由我的老师创建的,在上一个程序中运行良好,因此我认为这不是问题所在
Netbeans给出的错误是
g++-headerpad\u max\u install\u name-o
cs215pgm5.app/Contents/MacOS/cs215pgm5 mainForm.o image.o cs215pgm5.o
main.o moc_mainForm.o-F/Library/Frameworks-L/Library/Frameworks
-framework QtGui-架构x86_64的框架QtCore未定义符号:“FillerImage::FillerImage(std::basic_字符串,std::allocator>)”,引用自:
cs215pgm5.o ld中的loadFillerImagesFromFolder(std::basic_字符串,std::allocator>):
未找到架构x86_64 collect2的符号:ld返回1
退出状态生成::[cs215pgm5.app/Contents/MacOS/cs215pgm5]错误1
生成失败(退出值2,总时间:131ms)
感谢您提供的帮助。您的构建中似乎没有包含
fillerimage.cpp
。如果您确实在使用Qt,那么它可能不会作为Qt应用程序的.pro文件中的源代码列出。谢谢,这非常有效。我甚至没有看Qt方面的东西,因为讲师提供了所有这些文件。我们实际上还没有涵盖任何Qt。
#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;
}