this-pointer Questions

1

Solved

I struggle to find resources on this, and yet, so many of my classes are running into this error when I compile my code on the latest Java (21). Here is a code example. public class ThisEscapeExamp...
Whet asked 28/9, 2023 at 2:30

2

Solved

Since std::function can hold member functions, so it must store a pointer to the object instance somewhere. How can I fetch the this pointer from a std::function that holds a member function?
Marielamariele asked 1/4, 2013 at 16:53

1

Solved

I have an object that is related to some file stored on the disk. The object's constructor accepts this file as an argument, reads it and creates an actual object with the settings depending on the...
Ovenware asked 18/12, 2021 at 9:51

2

Solved

The examples I have found that capture this in a lambda use it explicitly; e.g.: capturecomplete = [this](){this->calstage1done();}; But it seems it is also possible to use it implicitly; e.g...
Flied asked 11/11, 2019 at 15:23

12

Solved

I asked myself whether the this pointer could be overused since I usually use it every single time I refer to a member variable or function. I wondered if it could have performance impact since the...
Hypertrophy asked 12/11, 2018 at 15:1

3

Let's say I have two ES6 classes like this: class Base { static something() { console.log(this); } } class Derived extends Base { } And then I make a call like this: Derived.something(); ...

3

Solved

This is a follow-up of these questions. Consider the following code: struct A { private: A* const& this_ref{this}; }; int main() { A a{}; (void)a; } If compiled with the -Wextra, both G...
Prosthesis asked 12/9, 2016 at 12:7

3

Solved

Returning reference to this object is often used in assignment operator overloading. It is also used as a base for named parameters idiom which allows to initialize object by chain of calls to sett...
Zeiger asked 27/2, 2016 at 11:55

2

Solved

I'm reading this article "Virtual method table" Example in the above article: class B1 { public: void f0() {} virtual void f1() {} int int_in_b1; }; class B2 { public: virtual void f2() {} ...
Taranto asked 10/6, 2015 at 20:45

3

I need reliable information about "this" subject: class MyClass, public QWidget { public: MyClass( QWidget * parent = NULL ) :QWidget( parent ), mpAnotherWidget( new QWidget( this ) ){}; privat...
Fortunio asked 1/4, 2015 at 11:40

2

Solved

In book "C++ Concurrency in Action" §3.3.1, when introducing thread-safe lazy initialization of a class member using std::call_once(), it gives the following example: #include <mutex> stru...
Uniaxial asked 21/4, 2014 at 12:20

2

Solved

Let's take the following example of a data structure (Node) that represents a tree of child nodes. The set of child nodes for each object is stored in a map> class Node; typedef std::shared_ptr&lt...
Ethylene asked 5/3, 2014 at 6:41

4

Solved

As mentioned in the title, I would like to know about the type of 'this' pointer. I'm working on a project and I observed that the type of 'this' pointer is "ClassName * const this" on windows us...
Bulkhead asked 20/5, 2011 at 3:44

4

Solved

i have main class that i like to pass its pointer reference to on of the objects i creating but it gives me error : Error 1 error C2664: 'GameController::GameController(GameLayer *&)' : can...
Salic asked 1/9, 2013 at 9:2

1

Solved

In The this pointer [class.this], the C++ standard states: The type of this in a member function of a class X is X*. i.e. this is not const. But why is it then that struct M { M() { this =...
Quiescent asked 17/6, 2013 at 12:4

6

Solved

This earlier question asks what this[0] means in C#. In C++, this[0] means "the zeroth element of the array pointed at by this." Is it guaranteed to not cause undefined behavior in C++ to refer to...
Susiesuslik asked 20/5, 2013 at 17:53

6

Solved

Where exactly is the 'this' pointer stored in memory? Is it allocated on the stack, in the heap, or in the data segment? #include <iostream> using namespace std; class ClassA { int a, b; ...
Jab asked 16/5, 2013 at 10:54

2

Solved

The following code won't compile. Why? class A { int j; void f( int i = this->j ); } Edit, for clarity. This is what I was trying to do, using less lines of code... class A { void f...
Providential asked 10/10, 2012 at 20:57

2

Solved

I am currently trying to learn how to use smart pointers. However while doing some experiments I discovered the following situation for which I could not find a satifying solution: Imagine you hav...
Dwanadwane asked 29/7, 2012 at 16:47

1

Solved

I'm getting this weird error: error C2663: 'sf::Drawable::SetPosition' : 2 overloads have no legal conversion for 'this' pointer I think it has something to do with const mismatches but I ...
Both asked 10/7, 2011 at 4:55

4

Solved

OK, I started using shared-pointers and pass shared-pointers as much as possible. No conversion to raw pointers anymore. This works good, except in this specific case: Suppose we have a class that...
Paperboard asked 2/2, 2011 at 8:33

4

Solved

I need to understand this pointer concept, preferably with an example. I am new to C++, so please use simple language, so that I can understand it better.
Warren asked 19/12, 2010 at 15:36

8

Solved

I have a weird problem with a this-pointer in a base-class destructor. Problem description: I have 3 classes: A1, A2, A3 A2 inherits publicly from A1 and inherits privately from A3 class A2:private...
Calliper asked 7/12, 2010 at 15:0

2

Solved

I am still far away from mastering C#, but the child in me is pushing me to continue improving my programming day by day. When I make a WinForms application I want to change and use lot of controls...
Cockcroft asked 6/8, 2010 at 23:20

4

Solved

Is there a way to force the this keyword to act as a ref argument? I would like to pass in a visitor that modifies multiple properties on the object, but this only wants to act like a value paramet...
Martel asked 15/4, 2010 at 16:13

© 2022 - 2024 — McMap. All rights reserved.