I have a simple class with one attribute std::unique_ptr<unsigned char[]>
in C++. I want to have a function that converts string to std::unique_ptr<unsigned char[]>
, other to convert float to std::unique_ptr<unsigned char[]>
, and a third to return the attribute std::unique_ptr<unsigned char[]>
. My header is compiling but the source CPP is not. Even the return attribute is not compiling.
#include <memory>
class SkinnyBuffer {
private:
std::unique_ptr<unsigned char[]> _buff;
public:
~SkinnyBuffer();
SkinnyBuffer();
void setBuffValue(float f);
void setBuffValue(std::string str);
std::unique_ptr<unsigned char[]>* getBuffValue();
};
#include "utils/SkinnyBuffer.h"
SkinnyBuffer::~SkinnyBuffer() { }
SkinnyBuffer::SkinnyBuffer() { }
void SkinnyBuffer::setBuffValue(float f) {
// How to implement it
_buff = f;
}
void SkinnyBuffer::setBuffValue(std::string str) {
_buff = std::unique_ptr<unsigned char[]>(str.data(), str.data() + str.length());
}
std::unique_ptr<unsigned char[]>* SkinnyBuffer::getBuffValue() {
return &_buff;
}