wind_2067 2022-05-06 19:15 采纳率: 100%
浏览 14
已结题

如何在 类 中定义 有含参数的构造函数 的 对象,且 对象的参数需处理后传入

问题相关代码

在WinClass.h中

class Window
{
  //......
public:
  Window();
  Direct direct;
private:
  HWND hWnd;
  int height;
  int width;
}

Window::Window()
  :
  direct(hWnd, width, height)  //问题出在此处,希望能在hWnd赋值后,再进行初始化
{
  RECT wr;
  wr.left = ......;
  wr.right = ......;
  wr.top = ......;
  wr.bottom = ......;

  hWnd = CreateWindow(…wr…);  //此处要把wr传入
};

在DirectClass.h中

class Direct
{
  friend class Window;
public:
  Direct(HWND, int, int);
private:
  HWND hWnd;  //实际上是想把参数传递到DirectClass内部,实在不行就类中类吧~
  int width;
  int height;
}

Direct::Direct(HWND hWnd, int width, int height)
  :
  hWnd(hWnd),
  width(width),
  height(height)
{}
我想要达到的结果

Window类 中的hWnd(处理后)、widthheight传入Direct

WindowDirect
hWndhWnd(CreateWindow(wr))hWnd
height不处理width
height不处理height
  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 5月14日
    • 修改了问题 5月9日
    • 创建了问题 5月6日

    悬赏问题

    • ¥20 抖音商城拉码器安卓报错求解决办法或者有新的拉码脚本也可以介绍一下
    • ¥15 MPLAB IDE V2.35 报错make[2]: *** [build/default/production/_ext/1472/MSSP_I2C.p1] Error 1
    • ¥15 新唐M451 DTMF检测和发送代码修改
    • ¥15 在国外文献网站里点击view pdf 加载异常缓慢甚至加载不出来。
    • ¥65 python批量提取发票的信息
    • ¥15 虚幻五引擎内容如何上传至网盘?
    • ¥15 使用mmpose库时出现了问题
    • ¥15 IRI2016模型matlab运行报错
    • ¥50 bat怎么设置电脑后台自动点击网页指定词运行脚本,输入指定网页链接,指定点击词,指定间隔时间,指定网页出现的词,指定网页出现词出现后后点击锁定,放在后台运行不影响前台鼠标工作
    • ¥20 20CrMnMo的高温变形抗力