2013-07-02 58 views
2

這可能很簡單,但我無法弄清楚。未定義的靜態方法引用

在我main.cpp中我有:

Image image("/path/to/image.png"); 
int* h = ImageProcessor::dailyPrices(image); 

在我ImageProcessor.h我:

//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); 
}; 

而在ImageProcessor.cpp我有

int* dailyPrices(const Image& abp_chart) 
{ 

但在嘗試編譯後,我在main.cpp中收到以下錯誤:

path/to/VendBot.cpp:17: undefined reference to `ImageProcessor::dailyPrices(Magick::Image const&)' 
+0

int * ImageProces sor :: dailyPrices(const Image&abp_chart)' –

+0

[與g ++鏈接時未定義對函數的引用]的重複(http://stackoverflow.com/questions/7043333/undefined-reference-to-a-function-when-與g)鏈接 –

+0

織補。更多的工作來找到重複而不是回答。並沒有rep的收益。 –

回答

4

定義dailyPrices功能,當你缺少類名:

int* ImageProcessor::dailyPrices(const Image& abp_chart) 
// ______________^ 
{ 
    // 
} 
+0

是的,每個人都是100%正確的。 D'哦!只要它讓我接受這個答案。 – Outback

0

您需要添加ImageProcessor::到你的方法定義:

int* ImageProcessor::dailyPrices(const Image& abp_chart) 
    ^^^^^^^^^^^^^^^^ 
0

dailyPrices必須在ImageProcessor命名空間:

int* ImageProcessor::dailyPrices(const Image& abp_chart) 
相關問題