currently I'm trying to run some code that I received from lynda.com but it is spitting out an error. The file I'm trying to compile is as follows, only including the calls to strnlen (strc.cpp):
#include <cstdio>
#include <cstring>
#include <memory>
#include "strc.h"
...
strc::strc() : data(nullptr) {
msg("default ctor");
}
strc::strc(const char * s) {
size_t slen = strnlen(s, _maxlen);
data = new char[slen + 1];
data[slen] = 0;
memcpy(data, s, slen);
msg("cstring ctor");
}
strc::strc(const strc & f) {
size_t slen = strnlen(f.data, _maxlen);
data = new char[slen + 1];
data[slen] = 0;
memcpy(data, f.data, slen);
msg("copy ctor");
}
...
To compile this I am running:
g++ -c strc.cpp -o strc.o -std=c++11
I've tried replacing cstring with string.h and I've even tried but std:: in front of strnlen. Any help in this matter would be greately appreciated
Aucun commentaire:
Enregistrer un commentaire