How do I get the name of an object that's been created through it's class?

I'm skimmed the code down to only highlight what I'm having trouble with. I have a class that creates a window. I want to be able to save the name of the object that's created when the class is initialized so that other objects know which window to draw on. Here is my code. What I can't figure out is how to pass the OBJECT name to the setActiveWindow() function...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

//In a global header file

extern window *_activeWindow;

void setActiveWindow(window *const w) { _activeWindow = w; }


//In a window.h file

class window {
public:
  window() { _buildWindow(800,600); }

private:

  _buildWindow(unsigned int width, unsigned int height) {
    //... do some stuff to create the window
	
    //set THIS window to the ACTIVE window
    setActiveWindow(this);
  } 
  

  unsigned int _width, _height;
};
Do you mean object name or object type (class) name?

if you mean object type name you can look into RTTI

if you mean object name you will have to store this yourself as a member.
Topic archived. No new replies allowed.