Achiko Mezvrishvili
Achiko Mezvrishvili

Reputation: 226

C++ auto issue or my mistake ?!

Is auto universal and works with any API, or i am not using it correctly i guess should be work in this case but error, if i shall change it with concrete type will work, but why ?

//  Set  vertex  buffer
auto  stride = m_FullScreenVTFTonemapPass.stride;
auto  offset = m_FullScreenVTFTonemapPass.offset;
m_pD3DDevice->IASetInputLayout( m_FullScreenVTFTonemapPass.IALayout );
m_pD3DDevice->IASetVertexBuffers ( 0, 1, &m_FullScreenVTFTonemapPass.VBdata, &stride, &offset );
m_pD3DDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP );

in IASetVertexBuffers() function stride and offset should be referenced but errors are popping up , if i'll change one of them stride or offset with UINT it works but why auto does not work ?!

Upvotes: -1

Views: 230

Answers (3)

kaiser
kaiser

Reputation: 1009

Use auto for iterators and loops only. In my opinion using auto is a bad habit.

If you'll visit your code days or weeks later, you will hate yourself for using auto at every possible variable. And if there is a other coder who have to read your code try to avoid it completely.

In your special case? What do you thing will be better when using auto here? UINT and auto has both 4 letters, so lazyness can't be the reason. If you're looking at your code and you see a UINT you will immediatly know what type the variable is.

Upvotes: 0

Achiko Mezvrishvili
Achiko Mezvrishvili

Reputation: 226

I have solved the issue was IASetVertexBuffer() needs two UINT parameters and my auto declaration was getting two simple integer(stride, offset) that was an error. IASetVertexBuffer() couldn't cast from int to UINT* parameters. That's it.

auto  stride = quad->stride;
auto  offset = quad->offset;
m_pD3DDevice->IASetInputLayout( quad->IALayout );
m_pD3DDevice->IASetVertexBuffers(0, 1, &quad->VBdata, (UINT*)&stride, (UINT*)&offset);
m_pD3DDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP );

P.S. Anyway if i will insist to use auto then i will cast those values stride and offset with (UINT*) and that's it. Works without a problem.

Upvotes: 1

tofro
tofro

Reputation: 6073

auto is not a type definition but a storage class (like static).

The compiler complains because you have told it how and where (in this case, on the stack) to store something, but not what the something should be.

You should add the type definition after the auto keyword, or as auto is the default anyways, replace it with the proper type.

UNIT stride = ......

Upvotes: -1

Related Questions