Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

In an example for a little game framework (that does work), there are the lines:

ID3D10Device* device;
ID3D10Buffer* pBuffer;

followed by the line

 device()->CreateBuffer(&bd, NULL, &pBuffer());

The third argument requires a pointer, so why do you need to put an ampersand before pBuffer? an ampersand gets a memory address right? But pBuffer is already a pointer so what does the ampersand do to it?

share|improve this question
4  
This probably belongs on StackOverflow, as it's not really game development related. Also, did you intend to write "device()" and "pBuffer()" in your third line? That seems like a typo; at the very least it changes the meaning of the code somewhat. –  Josh Petrie Sep 23 '11 at 14:51

2 Answers 2

up vote 9 down vote accepted

As described in the ID3D10Device::CreateBuffer page, this function simply requires a pointer to a pointer which is used to contain the output of the function.

HRESULT CreateBuffer(
  [in]   const D3D10_BUFFER_DESC *pDesc,
  [in]   const D3D10_SUBRESOURCE_DATA *pInitialData,
  [out]  ID3D10Buffer **ppBuffer
);

As always in C/C++, adding an & simply returns the address of the variable. In this case, the address of the pointer.

share|improve this answer

The & is also used as a reference operator. It returns the address of the variable it's referencing too. If you had a function that took the pointer directly as a parameter, then the function will be working directly with the pointer (useful for pointer arithmetic).

Pointer pointers to resources are quite common in the D3D APIs. You usually don't want to access them directly as it's not of any benefit.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.