Hi there,

I was wondering about something I noticed lately. I've been re-doing the dialog box program I wrote some time back to use a virtual class base-inherit style interface system. It means any code in the main program can call functions inside a DLL where all the DirectX stuff (or other API if you were using one) is stored. That way the rendering specific stuff says away from the main program.

It's an idea I got from an old book I've kind of adopted as a personal code bible. Was trickier to implement than I thought. Obviously delegating things like this through an interface can cause issues with acquiring valid pointers to objects and thus functions etc... I sorted it out in the end without having to make every function in the rendering class static (which would have looked bad) but I noticed this:

Code:
LONG_PTR ptr = GetWindowLongPtr(GetParent(hDlg), GWLP_USERDATA);
static D3DRenderer* pD3DRenderer = reinterpret_cast<D3DRenderer*>(ptr);

....sometime later

pD3DRenderer->LogResolution();
And a short part of the LogResolution() function:

Code:
UINT count = 0;
UINT flags = 0;
UINT refreshRate = 0;

IDXGIAdapter* adapter = nullptr;
IDXGIOutput* output = nullptr;
mResolutionPair.clear();
Note the last variable at the end. It's a vector, not that that's important really I guess this would apply to any variable. My question is...

How does this function know that the class data member mResolutionPair is tied to a specific object? It's not a static data member and nowhere in the function is any reference made to the actual object it belongs to. Yet it works.

Does C++ by default use the object that called the function as its reference to where variables and functions are stored? So if I called the function:

Code:
pD3DRenderer->LogResolution();
Does that mean that LogResolution() in this case uses the data stored in pD3DRenderer as its default location for stuff?

Kinda had me a bit puzzled.

Thanks