gpt4 book ai didi

c++ - 错误: …protected functions

转载 作者:行者123 更新时间:2023-12-02 11:11:00 25 4
gpt4 key购买 nike

我试图通过使用其他代码包中的Make方法来编译flann,但是在flann二进制文件'./flann/util/matrix.h:75'中遇到了有关 protected 函数的错误。
谁能帮我解决此错误?
我真的是编程的新手,请尽可能简单! :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_

最佳答案

您应该使用Matrix<T>而不是未键入的Matrix_类。然后,您可以使用ptr获取指向数据的类型化指针,或者使用[]运算符获取对特定元素的访问权限。

关于c++ - 错误: …protected functions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18639221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com