问题
This is probably something simple but I can't figure it out.
In my main.cpp I have:
Image image("/path/to/image.png");
int* h = ImageProcessor::dailyPrices(image);
And in my ImageProcessor.h I have:
//Maybe something is wrong with this? I am trying to forward declare.
namespace Magick
{
class Image;
}
class ImageProcessor {
public:
ImageProcessor();
virtual ~ImageProcessor();
static int* dailyPrices(const Magick::Image& abp_chart);
};
And in ImageProcessor.cpp I have
int* dailyPrices(const Image& abp_chart)
{
But upon attempt to compile I receive the following error in my main.cpp:
path/to/VendBot.cpp:17: undefined reference to `ImageProcessor::dailyPrices(Magick::Image const&)'
回答1:
You are missing the class name when defining the dailyPrices
function:
int* ImageProcessor::dailyPrices(const Image& abp_chart)
// ______________^
{
//
}
回答2:
You need to add ImageProcessor::
to your method definition:
int* ImageProcessor::dailyPrices(const Image& abp_chart)
^^^^^^^^^^^^^^^^
回答3:
dailyPrices needs to be in the ImageProcessor namespace:
int* ImageProcessor::dailyPrices(const Image& abp_chart)
来源:https://stackoverflow.com/questions/17428049/undefined-reference-to-static-method