boolean has different values depending on the thread [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a multi threading application in c++ in which I create an instance of a class and in it there is a boolean which I set to 'false'.
The case is, when in another thread I try to access this instance and get the boolean, it does not has the value 'false', instead of it, it has a random int value, like 62, ...
What is going on?

Maybe it was uninitialized initially? Then your another thread sees old cached value because even bool should be synchronized between threads.

Related

Terminate a c++ string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Is there a way to terminate a C++ string at any arbitary location. This is very easy in C as we can just insert a null character wherever we want. But how can the same be achieved in C++ String.
For example, Let's consider the following example,
string str = "This is Stack OverflowXXXX";
Now I want to terminate this string so that I would get "This is Stack Overflow".
Yep! Use string::erase:
str.erase(k);
will erase all characters from position k forward. There's no way to "undo" this to get those characters back, though.
Hope this helps!

in C program if statement is ignored while runtime [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
While debugging I found in "else if" part the if(temp->parent==temp1) statement is not checking true or false. Control directly jumps to the Send() function. Please let me know where it is going wrong.
else if(I_Send(my_rank,global_parent,&dest,num_procs))
{
if(temp->parent==temp1)
{
fix_node[my_rank]==temp;
}
Send(fix_node[my_rank],L,sz_vec[fix_node[my_rank]->node_num],fix_node[my_rank],dest,temp1);
temp1=temp1->parent;
if(temp1!=NULL)
local_parent=temp1->node_num;
}
The code inside the if body has no effect...
fix_node[my_rank]==temp;
I think you meant to do an assignment (=) instead of comparison (==)

Bindind to keys C++ [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
Hello there I am a realative newbie when it comes to using different "commands" in order to achieve things so I was wondering if any of you know a way to bind a key to do a certain task anywhere in the programme ,so I would be able to display a function for example and after the display finishes the programme carries on normally like nothing happened and then that same key on any other push would still do the display . Thanks in advance
Plain C++ does not have any concept of "key binding". The platform (e.g., the operating system) has this knowledge and it provides some libraries to handle it. So, you must provide more information about the operating system, or use a cross-platform library like Qt.

return this-> command in C++ [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
return this->
what is that mean in C++
..
using namespace std;
IOM ConfigurationManager::getIOM(int iomId) {
return this->IOMs[iomId];
..
the relevant part of the whole code is above.
The code that I wrote is from a huge project which was waiting for someone to finish. I am not good at C++ but I need to learn more not to lose that job. Anyway, the project is full of "return this->...." which I thought unnecessary, that's why I asked is there smt special that we should use that notation
This piece of code simply means that the IOM at index iomId in the IOMs array in the ConfigurationManager object is returned. Note that the this->IOMs is the same as IOMs in this case, thus it seems the this is only there for clarity.
this is a pointer to the current object. The -> operator allow you to access a member inside a pointer to an object.
Thus return this->IOMs[iomID] returns the IOM object in the current ConfigurationManager at index iomID.

Finding value of int x [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
int x;
x=x+30;
cout << x;
the output will be 33, why is it so?
I didn't even declare x as 3.
Can someone guides me? Thanks!
Using an uninitialized variable is undefined behavior. You got 33 due to an unreliable sequence of implementation quirks. The program is free to produce any value at all, fail to compile, or hire an assassin to stab you.
In C++, variables are given space (memory allocation) by default equal to the size of the variable, but they are not given values by default.