CPP Pointers to Classes

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Doing some experimenting today with pointers to classes the fundamental difference between C pointers to functions and CPP pointers to classes "clicked".

in C the pointer to a function is a pointer to an arbitrary code address. The only requirement is that a function with the same signature as is declared for the pointer should reside there.

in CPP the pointer is actually to the data. A the class pointer is for a specific class type and there is only one instance of the class code... the compiler already knows where the code is located.

This is probably obvious to many (all?) of the forum members.... but it was a light bulb moment for me and I thought I should share it. I was thinking way too hard to try and understand what was going on :o

on the other hand pointers to class member functions are just too complicated and lead to the "why are vtabs in ram discussion?" :x

regards
Greg

Last Edited: Sun. Apr 7, 2013 - 11:04 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A class is just a souped up struct{} so just think of it as a pointer to struct.