*this parameter to a function [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
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.

Related

Construct a span<shared_ptr<T>> from an array<shared_ptr<void>> [closed]

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 2 years ago.
Improve this question
I've got an std::array<std::shared_ptr<void>, N>, and I have methods for accessing parts of this buffer as different types, which I would like to use std::span<std::shared_ptr<T>> for.
Is there a way to construct a span like this without invoking UB?
No, this is impossible: regardless of the ability to convert void* to T*, you can’t convert void** (a pointer to your first pointer) to T** because there are no actual T* objects there, and you certainly can’t convert std::shared_ptr<A>* to std::shared_ptr<B>* for any distinct A and B—std::shared_ptr<T> isn’t just a T* internally (because of the control block), and even if it were you’re not allowed to “unwrap” arrays of structures and treat them as arrays of their contents (with the magic exception of std::complex).

What's the difference between there two pointer statements [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Just wondering what the difference was between these two lines of code and exactly what they are doing:
p*++
++*p
*p is value of the pointer pointing to.
also * uses as multiplication operator (int a = 5*6;)
p++ is post increment the value of p
++p is pre increment the value of p.
so
++*p is pre increment the value of pointer point to.
p*++ gives you a compile error, because of no meaning

Is it dangerous to use the following in vector? [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 member variable vector<Foo> m_list
In some methods, I create the auto variable a in Foo type
Foo a;
m_list.push_back(a)
Is it possible that m_list[0] becomes invalid?
Class Foo
{
vector<int> _colors;
vector<int> _flowers;
}
You seem to be worried about what will happen to m_list[0] once the local variable a goes out of scope. Don't be. push_back actually pushes a copy of a into m_list. Now; that may cause other problems if you were expecting a and m_list[0] to be the same thing, but as long as ClassA has a functioning copy constructor (and based on your edit, it does), trying to access a destroyed object won't be one of them.

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.