Undefined reference to static method

无人久伴 提交于 2020-01-05 02:41:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!