DirectXTK SimpleMath::Rectangle to RECT?

Started by
2 comments, last by trojanfoe 6 years, 1 month ago

I hope this is the right place to ask questions about DirectXTK which aren't really about graphics, if not please let me know a better place.

Can anyone tell me why I cannot do this:


DirectX::SimpleMath::Rectangle rectangle = {...};
RECT rect = rectangle;

or


RECT rect = static_cast<RECT>(rectangle);

or


const RECT rect(m_textureRect);

despite Rectangle having the following operator RECT:


operator RECT() { RECT rct; rct.left = x; rct.top = y; rct.right = (x + width); rct.bottom = (y + height); return rct; }

VS2017 tells me:


 error C2440: 'initializing': cannot convert from 'const DirectX::SimpleMath::Rectangle' to 'const RECT'

Thanks in advance

Indie Game Dev

Advertisement

operator RECT(){}

will not allow you to convert to a const RECT, you need a operator RECT() const {} for this (if i remember well)

Try just with


RECT rect = (RECT)rectangle;

should work.

(i'm going by memory, cannot test it now)

I thought the same and hacked a const in and it made no difference.  Doesn't really matter now - I've just added a conversion method to my Util class, however I was a bit stumped as to why it didn't work and wondered if it was a  well known issue in this forum.

Thanks for your reply.

Indie Game Dev

This topic is closed to new replies.

Advertisement