c++compiler-errorsflann

Error: ...protected functions


I tried to compile flann by uses Make method from pack of another codes but I got this error about protected functions in one of the flann binary files './flann/util/matrix.h:75' Can any one help me to fix this error? I'm really new in programming, plz be simple as u can! :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

This is 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_

Solution

  • You should be using Matrix<T> instead of the untyped Matrix_ class. Then you can use ptr to get a typed pointer to the data, or the [] operator to get access to a specific element.