Object pointer points to?

Hi everyone,

I was just wondering, I know about pointers and now know (little) of objects.
I just came up wondering, what exactly goes beyond the scene when I create a pointer to an object. In terms of memory, what does it "point" too?

As an object is really a collection of data members and methods, I reckon it can not point to just one thing, so I'm guessing it might create an array of some sort to other pointers. If someone could elaborate a bit further, I'd be really grateful.
Last edited on
Stop wondering, start experimenting.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class test
{
  public:
  int i;
  double j;
  float k[20];
};

#include <iostream>

int main()
{
  test testObject;
  std::cout << "Address of test object is: " << &testObject << std::endl;
std::cout << "Address of test object's i variable is: " << &(testObject.i) << std::endl;
std::cout << "Address of test object's j variable is: is: " << &(testObject.j)  << std::endl;
std::cout << "Address of test object's k variable is: is: " << &(testObject.k)  << std::endl;
}


Output:
Address of test object is: 0x7ffff384a280
Address of test object's i variable is: 0x7ffff384a280
Address of test object's j variable is: is: 0x7ffff384a288
Address of test object's k variable is: is: 0x7ffff384a290



So, the pointer to the object has the same value as the pointer to the first member variable. It does point to just one thing. The beginning of the object's existence in memory.
Last edited on
Thanks for the quick reply; in the future, I'll definitely try to experiment more before making such a post.
Topic archived. No new replies allowed.