I have the following error :
Error : Undefined Reference to "Image2Grey::Image2Grey(int, int)"
I have a template Image2, and a class Image2Grey : Image2
The arborescence is :
\-folder1/
\image2.h
\image2.hpp
\image2Grey.cpp
\image2Grey.hpp
\-folder2/
\main.cpp
When I try to create a new object Image2Grey, I have the error, like if my constructor does not exist. I don't understand what i am doing wrong.
Here is my code :
/** main.cpp **/
#include "../folder1/image2grey.hpp"
int main(int argc, char *argv[]) {
Image2Grey img(6, 10);
return 0;
}
/** image2.h **/
template<typename T>
class Image2D {
public:
Image2D(int width, int height);
protected:
T *image;
};
/** image2.hpp **/
#include "image2d.h"
template<typename T>
Image2D<T>::Image2D(int width, int height){
image = new T[width * height];
}
/** image2grey.hpp **/
#include "image2d.h"
class Image2Grey : Image2D<unsigned char> {
public:
Image2Grey(int width, int height);
/** image2grey.cpp **/
#include "image2grey.hpp"
Image2Grey::Image2Grey(int width, int height) :
Image2D<unsigned char>(width, height) {}
If you have any idea about why I have this error.. Thanks