473,289 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

address of class from within class method

Is there a way to get a pointer to a class from inside one of the
class's methods?

Jun 2 '06 #1
12 2855
pe****************@hotmail.com wrote:
Is there a way to get a pointer to a class from inside one of the
class's methods?


Every class can refer to itself by a "this" pointer. Look it up in your
favorite C++ book.

Cheers! --M

Jun 2 '06 #2
pe****************@hotmail.com wrote:
Is there a way to get a pointer to a class from inside one of the
class's methods?


What do you mean by a "pointer to a class"? A class is not an object,
it is a type. You can get a pointer to the current object by using the
keyword "this".
Jun 2 '06 #3
mlimber wrote:
pe****************@hotmail.com wrote:
Is there a way to get a pointer to a class from inside one of the
class's methods?


Every class can refer to itself by a "this" pointer. Look it up in your
favorite C++ book.


No, every *object* can refer to itself by a "this" pointer. A class is
not an object, and therefore doesn't have an address, which a pointer
can point to.

Jun 2 '06 #4
red floyd wrote:
pe****************@hotmail.com wrote:
Is there a way to get a pointer to a class from inside one of the
class's methods?


What do you mean by a "pointer to a class"? A class is not an object,
it is a type. You can get a pointer to the current object by using the
keyword "this".

Foot note: A class is a type, see 3.9.2/1
Jun 2 '06 #5

red floyd wrote:
What do you mean by a "pointer to a class"? A class is not an object,
it is a type. You can get a pointer to the current object by using the
keyword "this".


I meant an instance of a class.

Will the keyword "this" give me the address of the instance of the
class that called the class method which is using the keyword "this"?

Jun 2 '06 #6
On Fri, 02 Jun 2006 12:56:33 -0700, peregrine_falcon12 wrote:
Is there a way to get a pointer to a class from inside one of the class's
methods?


This may sound like nitpicking... but a class doesn't have an address. A
class merely describes what an object will "look like". _Instances_ of a
class have addresses.

So, could you restate your question?
Jun 2 '06 #7

Andre Kostur wrote:
On Fri, 02 Jun 2006 12:56:33 -0700, peregrine_falcon12 wrote:
Is there a way to get a pointer to a class from inside one of the class's
methods?


This may sound like nitpicking... but a class doesn't have an address. A
class merely describes what an object will "look like". _Instances_ of a
class have addresses.

So, could you restate your question?


I meant an instance of a class.

Jun 2 '06 #8

pe****************@hotmail.com wrote:
red floyd wrote:
What do you mean by a "pointer to a class"? A class is not an object,
it is a type. You can get a pointer to the current object by using the
keyword "this".


I meant an instance of a class.

Will the keyword "this" give me the address of the instance of the
class that called the class method which is using the keyword "this"?


no.

Jun 2 '06 #9
pe****************@hotmail.com wrote:
Will the keyword "this" give me the address of the instance of the
class that called the class method which is using the keyword "this"?


Your phrase "the instance of the class that called the class method" is
not clear. Consider this:

struct A;

void Baz( A* ) {}

struct A
{
void Foo() { Baz( this ); } // Ok
};

struct B
{
void Bar( A& a )
{
a.Foo(); // Ok
Baz( this ); // Error
}
};

int main()
{
A a;
B b;
b.Bar( a );
}

In this example, the class instance that calls A::Foo() is an instance
of B. Within A::Foo(), "this" refers to an A object. Within B::Bar(),
"this" points to a B object, which is why the call to Baz generates an
error in B::Bar().

Cheers! --M

Jun 2 '06 #10
red floyd wrote:
mlimber wrote:
pe****************@hotmail.com wrote:
Is there a way to get a pointer to a class from inside one of the
class's methods?


Every class can refer to itself by a "this" pointer. Look it up in your
favorite C++ book.


No, every *object* can refer to itself by a "this" pointer. A class is
not an object, and therefore doesn't have an address, which a pointer
can point to.


Sorry. I got typing too quickly.

Cheers! --M

Jun 2 '06 #11
Problem Solved!!!

Thanx mlimber!

Jun 2 '06 #12
On Fri, 02 Jun 2006 13:30:21 -0700, peregrine_falcon12 wrote:
Andre Kostur wrote:
On Fri, 02 Jun 2006 12:56:33 -0700, peregrine_falcon12 wrote:
> Is there a way to get a pointer to a class from inside one of the
> class's methods?


This may sound like nitpicking... but a class doesn't have an address.
A class merely describes what an object will "look like". _Instances_
of a class have addresses.

So, could you restate your question?


I meant an instance of a class.


OK, from inside any of your methods (except static methods), they all have
a pointer called "this" which points to the instance on which this method
was invoked.
Jun 2 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: | last post by:
Hi I have a list containing several instance address, for example: I'd like to invoke a method on each of these instance but I don't know : 1. if its possible 2. how to proceed
30
by: Neil Zanella | last post by:
Hello, Suppose I have some method: Foo::foo() { static int x; int y; /* ... */ }
0
by: landagen | last post by:
I am using the MethodRental class, but i noticed that you have to pass a byte for to replace the body of a method. The problem comes when i want to access a field within the class where I am...
5
by: Brett | last post by:
In a class, I have several Private subs. I declare an instance of the class such as: Dim MySelf as new Class1 within a private sub. The motive is to provide access to other subs within the...
7
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9...
6
by: roland.bali | last post by:
Hi, Here is the basic setup, my base class is Shoe which has a child class called Sandal. I would like to create objects by calling Sandal.Load. But without overloading Load in Sandal and...
4
by: toton | last post by:
Hi, How to find address of a class from inside? My class having a overloaded new & delete. new allocates the memory like void* operator new(std::size_t size) throw(){ cout<<"op new...
8
by: gilad | last post by:
hi, I would like to get the address of a class method in an instance. In the following sample the third like access the method. how can I get the address into a long variable - something like -...
1
by: Jamie J. Begin | last post by:
I'm very new to the world of Python and am trying to wrap my head around it's OOP model. Much of my OOP experience comes from VB.Net, which is very different. Let's say I wanted to create an...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.