sample.h < /p>
Код: Выделить всё
class Sample
{
private:
int id;
std::string text;
public:
Sample(int id);
void setId(int id);
int getId();
void setText(std::string txt);
std::string getText();
void loadText();
~Sample();
}
< /code>
sample.cpp[/b]
Sample::Sample(int id)
{
this->id = id;
}
void Sample::setId(int id)
{
this->id = id;
}
int Sample::getId()
{
return this->id;
}
void Sample::setText(std::string txt)
{
this->text = txt;
}
std::string Sample::getText()
{
return this->text;
}
void Sample::loadText()
{
this->text = "Loaded";
}
Sample::~Sample()
{
std::cout loadText();
const char* text = sample->getText().c_str();
std::cout getText();
const char* text = textCpy.c_str();
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/60555228/confusing-behavior-of-c-string-returns-and-c-str-casts[/url]