Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Currently, I have code like:
static YAML::Node *doc;
...
__attribute__((constructor)) void inityaml() {
doc = new YAML::Node;
parser.GetNextDocument(*doc);
}
The question is, is there any more C++-conventions-ish way to perform this task, like the use of a global reference or something?
Why not avoid heap allocation altogether?
i.e.
static YAML::Node doc;
...
void inityaml() {
parser.GetNextDocument(&doc);
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed yesterday.
Improve this question
I have header (*.hxx) and implementation (*.cxx) files.
Additionally, I don't want to put all my code into the header file.
I would like to keep the header file as small as it's possible.
In this case: how to declare inline method in my class?
question.hxx
class question
{
int get_value();
};
question.cxx
int question::get_value()
{
return 0;
}
A tiny sample code in C++.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
vector<char> vec;
vec.push_back(0x1);
char* a = "qwe";
I want to push a to the end of the vector.
You can use the .insert() member function with pointers standing in as iterators.
vec.insert(vec.end(), a, a+strlen(a));
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Can anybody check the below link and help me to understand and resolve it.
https://discuss.emberjs.com/t/disable-prototype-extension/16354
You have to put your EXTEND_PROTOTYPES flag into EmberENV.
ENV = {
...
EmberENV: {
EXTEND_PROTOTYPES: false
}
...
}
Check out ember-guides
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
All my attempts so far have failed.Basically when I return a copy of the internal char array of the string, that copy has to be released, but I don't know how to release it.Wrapping it in a smart pointer doesn't work out, since it's destructor gets called immediately after I return it.Must I implement something like a garbage collector just for the immutable string?
const std::string will be fine.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Is there any issue in the following code? I am told it's there, but I couldn't find it...
std::string fun(int i)
{
std::ostringstream t;
t<<"My int is "<<i<<returnSomething();
return t.str();
}
The code in the question is fine. It would be a problem if you returned a pointer into the local object (say that you returned a const char* obtained as t.str().c_str()) or if you returned a reference. But in your code, a copy of the internal string in the std::ostringstream is performed before the function completes (as part of the return statement), and before t gets destroyed, so it is fine.