2013-09-05 42 views
-1

我試圖編譯flann使用從另一個代碼包製作方法,但我得到了關於在一個flann二進制文件中的受保護函數的錯誤./flann/util/matrix.h: 75' 任何人都可以幫我解決這個錯誤嗎? 我真的很新,編程很簡單,因爲你可以! :P錯誤:...受保護的功能

g++ -I. -Iflann/src/cpp -c -o src/main.o src/main.cpp 
In file included from ./boost/asio/async_result.hpp:18, 
      from ./boost/asio.hpp:20, 
      from src/common.hpp:30, 
      from src/main.cpp:9: 
./boost/asio/detail/config.hpp:367:5: warning: #warning Please define _WIN32_WIN NT or _WIN32_WINDOWS appropriately. 
./boost/asio/detail/config.hpp:368:5: warning: #warning For example, add -D_WIN32_WINNT=0x0501 to the compiler command line. 
./boost/asio/detail/config.hpp:369:5: warning: #warning Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target). 
./flann/util/matrix.h: In function 'int cbir::main(int, char**)': 
./flann/util/matrix.h:75: error: 'flann::uchar* flann::Matrix_::data' is protected 
src/main.cpp:39: error: within this context 
Makefile:43: recipe for target `src/main.o' failed 
make: *** [src/main.o] Error 1 

這是matrix.h:

#ifndef FLANN_DATASET_H_ 
#define FLANN_DATASET_H_ 

#include "flann/general.h" 
#include <stdio.h> 

namespace flann 
{ 

typedef unsigned char uchar; 

class Matrix_ 
{ 
public: 

Matrix_() : rows(0), cols(0), stride(0), data(NULL) 
{ 
}; 

    Matrix_(void* data_, size_t rows_, size_t cols_, flann_datatype_t type, size_t stride_ = 0) : 
      rows(rows_), cols(cols_), stride(stride_) 
    { 
      data = static_cast<uchar*>(data_); 
      if (stride==0) stride = flann_datatype_size(type)*cols; 
    } 

    inline void* operator[](size_t index) const 
    { 
      return data+index*stride; 
    } 

    void* ptr() const 
    { 
      return data; 
    } 

    size_t rows; 
    size_t cols; 
    size_t stride; 
    flann_datatype_t type; 
protected: 
    uchar* data; 

}; 

template <typename T> 
class Matrix : public Matrix_ 
{ 
public: 
    typedef T type; 

    Matrix() : Matrix_() 
    { 
    } 

    Matrix(T* data_, size_t rows_, size_t cols_, size_t stride_ = 0) : 
     Matrix_(data_, rows_, cols_, flann_datatype<T>::value, stride_) 
    { 
    } 

    FLANN_DEPRECATED void free() 
    { 
      fprintf(stderr, "The flann::Matrix<T>::free() method is deprecated " 
        "and it does not do any memory deallocation any more. You are" 
        "responsible for deallocating the matrix memory (by doing" 
        "'delete[] matrix.ptr()' for example)"); 
    } 

    inline T* operator[](size_t index) const 
{ 
    return reinterpret_cast<T*>(static_cast<uchar*>(Matrix_::data)+index*stride); 
//  return (T*)(Matrix_::operator [](index)); 
} 

    T* ptr() const 
    { 
      return reinterpret_cast<T*>(Matrix_::data); 
    } 
}; 

} 

#endif //FLANN_DATASET_H_ 
+2

向我們展示一些代碼! – user1233963

+0

如果你只給出一些編譯器錯誤提示,沒有人會知道發生了什麼。粘貼一些片段代碼會更好。 – DarkHorse

+1

我在google上找不到一個版本的'matrix.h',它有一個可疑的行75或一個受保護的'data'屬性。你可以發佈你的一部分(或整個文件的鏈接)嗎? –

回答

0

您應該使用Matrix<T>,而不是無類型Matrix_類。然後,您可以使用ptr獲取指向數據的鍵入指針,或使用[]運算符訪問特定元素。