user11568109
user11568109

Reputation:

Is it possible to create a pointer to a class in C++

How can I create a pointer to a class. I assume, that classes exists somewhere in RAM, so, is it possible to get a pointer to it?
I don't mean a pointer to an object, I mean a pointer to the class itself (like a function pointer).

Upvotes: 9

Views: 1084

Answers (2)

MSalters
MSalters

Reputation: 179779

This is not possible. C++ has three types of pointers:

  1. Pointers to objects
  2. Pointers to functions
  3. Pointers to class members.

Classes are none of the above.

Upvotes: 4

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136208

I assume, that classes exist somewhere in the Ram

Classes do not exist at run-time, so you cannot take a pointer to a class.

Only objects exist at run-time.

Upvotes: 13

Related Questions