Hi there,
I was perusing through some code and I found this:
Code:
struct CD3DX12_RESOURCE_BARRIER : public D3D12_RESOURCE_BARRIER
{
CD3DX12_RESOURCE_BARRIER()
{}
explicit CD3DX12_RESOURCE_BARRIER(const D3D12_RESOURCE_BARRIER &o) :
D3D12_RESOURCE_BARRIER(o)
{}
static inline CD3DX12_RESOURCE_BARRIER Transition(
_In_ ID3D12Resource* pResource,
D3D12_RESOURCE_STATES stateBefore,
D3D12_RESOURCE_STATES stateAfter,
UINT subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
D3D12_RESOURCE_BARRIER_FLAGS flags = D3D12_RESOURCE_BARRIER_FLAG_NONE)
{
CD3DX12_RESOURCE_BARRIER result;
ZeroMemory(&result, sizeof(result));
D3D12_RESOURCE_BARRIER &barrier = result;
result.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
result.Flags = flags;
barrier.Transition.pResource = pResource;
barrier.Transition.StateBefore = stateBefore;
barrier.Transition.StateAfter = stateAfter;
barrier.Transition.Subresource = subresource;
return result;
}
.... code continues
};
So there's a struct defined as inheriting from another one and then some constructors. Then comes the static function. Inside the static function there is an object of this exact class type:
Code:
CD3DX12_RESOURCE_BARRIER result;
So I wonder how does this not cause some bizarre sort of declaration recursion as surely that means there will be another copy of the class, with another function of the same type with another object of the class type and then another and another...... Unlike a recursive function though there is no condition guaranteed to eventually cause one iteration of this to be firmly resolved. Rather like a room with two mirrors facing each other on opposite walls.
How does the compiler sort of know when to stop?
It's got me quite confused!, thanks