RECT,将自定义的RECT结构传递到需要RECT的函数中
RECT , passing a custom rect struct into a function that is requireing RECT
好的,所以我有一个自定义的rect函数。自定义矩形如下:
typedef struct tagRECTEx{
// long left;
// long top;
// long right;
// long bottom;
RECT dimensions;
int width()) {
return dimensions.right-dimensions.left;
}
int height(){
return dimensions.bottom - dimensions.top;
}
} RectEx;
现在不用说:
RECT windowrect;
windowrect = GetWindowRect(hWnd,&windowrect);
我希望它是这样的:
RectEx windowrectex;
windowrect = GetWindowRect(hWnd,&windowrectex);
....
现在它不会编译,因为它无法将rectex转换为tagRECT,好吧,我明白了,我理解了。
所以在过去的几天里,我一直在搜索自定义强制转换和重写运算符。
我甚至在尝试实现这样的东西:
GetWindowRect(hWnd, (RectEx)&windowrectex);
但不管我在做什么,我就是不知道如何让它发挥作用。
我想使用我自己的rect结构,因为它会自动为我获取rect的宽度和高度,而不是做rect.right-rect.left等。
如果你需要更多关于这个或任何事情的信息,请告诉我。
感谢
由于GetWindowRect
将LPRECT
作为第二个参数,因此无法传递RectEx
。
您可以使用RectEx
做些什么,您可以重载typecasting操作符,如下所示
operator LPRECT () const
{
return &dimensions;
}
但是,由于不希望进行类型转换,因此不建议重载类型转换。只有当你确信的时候才这样做。
只需从RectEx
内部传递RECT
。
RectEx windowrectex;
windowrect = GetWindowRect(hWnd,&windowrectex.dimensions);
或者,可以使RectEx
从RECT
继承并删除dimensions
。
或者,添加一个转换运算符,类似于dbasic建议的operator RECT*() const
。然后你会使用:
windowrect = GetWindowRect(hWnd,windowrectex);
相关文章:
- "error: no matching function for call to"构造函数错误
- 什么时候调用组成单元对象的析构函数
- 继承函数的重载解析
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- C++模板来检查友元函数的存在
- 递归函数计算序列中的平方和(并输出过程)
- 对RValue对象调用的LValue ref限定成员函数
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 为什么使用 "this" 指针调用派生成员函数?
- 将对象数组的引用传递给函数
- 函数调用中参数的顺序重要吗
- 函数向量_指针有不同的原型,我可以构建一个吗
- 使用不带参数的函数访问结构元素
- 代码在main()中运行,但在函数中出现错误
- 内置函数可查看CPP中的成员变量
- RECT,将自定义的RECT结构传递到需要RECT的函数中
- C++ 通过函数传递 std::shared_ptr<RECT>
- opencv:来自rect的Mat构造函数