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

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.

Related

boolean has different values depending on the thread [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
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.

Storing Objective-C class instance in C++ class [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
Is there a way to store an Objective-C class instance inside of a C++ class as a member?
You need to make a .mm file, and then you can use the features outlined here. See also a reference to Apple's old documentation on the hybrid language.

*this parameter to a function [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
I understand what this->function does but the code i'm looking at has
function_name(*this,param1,param2) and I'm not to clear on what that is supposed to do.
we are passing pointer to the object being worked on and two parameters to the function?
Your function:
function_name(*this,param1,param2)
takes, as first parameter, a T or T& (or const T&) (with T = type of the object this points to). The pointers this is being dereferenced, and like any pointer, the expression *x points to the value being pointed by x.
*this is not a pointer, it is the current object this pointed to.

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.

Is there a "generics-like" feature 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
I'm trying to create a list class in C++ similar to the lists in Java. Is there a way I can have it be able to list whatever object it wants to? The class resizes arrays to create the list, but what I need to do is find out the kind of object that's needed to store.
Yes, C++ has templates that can be used to create generic containers roughly similar to Java generic containers.
While your immediate reaction might be to assume that std::list is similar to a Java list, that would be a mistake. In Java, a list basically just means a sequence. In C++, a std::list is a linked list (which is rarely useful). Most of the time you want to use an std::vector (which is more like Java's ArrayList).
Yes, there is, and it's called Templates