Je dois par la force des choses quitter la programmation fonctionnelle pour me tourner vers du C++ et je galère.
Si quelqu'un à une minute ou deux pour lire ces quelques lignes de code et m'expliquer les messages d'erreurs à la compilation je lui en serais reconnaissant!
Les erreurs:
Code : Tout sélectionner
CMakeFiles/../bin/m2s1.dir/src/Image/Image8/Image8.cpp.o: In function `Image::Image(unsigned int, unsigned int)':
Image8.cpp:(.text._ZN5ImageC2Ejj[_ZN5ImageC5Ejj]+0x15): undefined reference to `vtable for Image'
CMakeFiles/../bin/m2s1.dir/src/Image/Image8/Image8.cpp.o: In function `Image8::Image8(Image8 const&)':
Image8.cpp:(.text._ZN6Image8C2ERKS_[_ZN6Image8C5ERKS_]+0x118): undefined reference to `Image::~Image()'
CMakeFiles/../bin/m2s1.dir/src/Image/Image8/Image8.cpp.o: In function `Image8::~Image8()':
Image8.cpp:(.text._ZN6Image8D2Ev[_ZN6Image8D5Ev]+0x2f): undefined reference to `Image::~Image()'
CMakeFiles/../bin/m2s1.dir/src/Image/Image8/Image8.cpp.o:(.rodata._ZTI6Image8[_ZTI6Image8]+0x10): undefined reference to `typeinfo for Image'
collect2: erreur: ld a retourné 1 code d'état d'exécution
make[2]: *** [../bin/m2s1] Erreur 1
make[1]: *** [CMakeFiles/../bin/m2s1.dir/all] Erreur 2
make: *** [all] Erreur 2
Classe Image
Code : Tout sélectionner
#ifndef _IMAGE_
#define _IMAGE_
class Image{
public:
Image(unsigned int w, unsigned int h) : _width(w), _height(h){}
virtual ~Image();
protected:
unsigned int _width;
unsigned int _height;
virtual void dump(std::ostream& stream) const;
friend std::ostream& operator<<(std::ostream& stream, Image const& image);
virtual int width() const {return _width;}
virtual int height() const {return _height;}
virtual int size() const {return _width * _height;}
virtual unsigned int valMax() const = 0;
virtual unsigned int getPixel(unsigned int i, unsigned int j) const = 0;
virtual bool setPixel(unsigned int i, unsigned int j, unsigned int v) = 0;
virtual Image* negative() = 0;
private:
};
#endif // _IMAGE
Code : Tout sélectionner
#include <iostream>
using namespace std;
#include "Image.h"
void Image::dump(ostream& stream) const{
stream << _width << ' ' << _height << endl;
}
ostream& operator<<(ostream& stream, Image const& image){
image.dump(stream);
return stream;
}
Code : Tout sélectionner
#define _IMAGE8_
#include "../Image.h"
class Image8 : public Image{
public:
Image8(unsigned int w, unsigned int h) : Image(w,h) {
char* _pixel = new char[size()];
for (int i=0; i<size(); i++) _pixel[i] = 0;
updateValMax();
}
Image8(Image8 const& image8) : Image(image8.width(), image8.height()) {
char* _pixel = new char[size()];
for (int i=0; i<height(); i++){
for (int j=0; j<width(); j++){
_pixel[i*width()+j] = image8.getPixel(i,j);
}
}
updateValMax();
}
virtual ~Image8(){delete _pixel;}
protected:
unsigned char* _pixel;
unsigned char _valMax;
virtual void dump(std::ostream& stream) const;
friend std::ostream& operator<<(std::ostream& stream, Image8 const& image8);
virtual void updateValMax();
virtual unsigned int valMax() const {return _valMax;}
virtual unsigned int getPixel(unsigned int i,unsigned int j) const {return (int)_pixel[i*width()+j];}
virtual bool setPixel(unsigned int i, unsigned int j, unsigned int v);
virtual Image8* negative();
private:
};
#endif //_IMAGE8_
Code : Tout sélectionner
#include <iostream>
using namespace std;
#include "Image8.h"
void Image8::dump(ostream& stream) const{
Image::dump(stream);
stream << valMax() << endl;
for (int i=0; i<height(); i++){
for (int j=0; j<width(); j++){
stream << ' ' << getPixel(i,j);
}
stream << endl;
}
}
ostream& operator<<(ostream& stream, Image8 const& image8){
image8.dump(stream);
return stream;
}
void Image8::updateValMax(){
int valMax(0);
for (int i=0; i<height(); i++){
for (int j=0; j<width(); j++){
valMax = valMax < getPixel(i,j) ? getPixel(i,j) : valMax;
}
}
_valMax = valMax;
}
bool Image8::setPixel(unsigned int i, unsigned int j, unsigned int v){
_pixel[i*width()+j] = v;
return true;
}
Image8* Image8::negative(){
int w(width()), h(height()), v(valMax());
Image8* out = new Image8(*this);
for (int i=0; i<h; i++){
for (int j=0; j<w; j++){
out->setPixel(i,j,v-getPixel(i,j));
}
}
return out;
}
Merci d'avance pour votre aide.
eatman.