加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 自己做一个班级朋友

发布时间:2020-12-16 10:20:59 所属栏目:百科 来源:网络整理
导读:编辑:看起来我完全被误导了.请关闭此帖子.嘎. 为了记录,以下编译和工作: class ForeverAlone{private: int m_friends; HANDLE m_handle;public: ForeverAlone() { m_handle = CreateThread(NULL,ForeverAlone::SadThread,reinterpret_castvoid*(this),NULL
编辑:看起来我完全被误导了.请关闭此帖子.嘎.

为了记录,以下编译和工作:

class ForeverAlone
{
private:
  int m_friends;
  HANDLE m_handle;

public:
  ForeverAlone()
  {
    m_handle = CreateThread(NULL,&ForeverAlone::SadThread,reinterpret_cast<void*>(this),NULL);
  }

  ~ForeverAlone()
  {
    if (m_handle != NULL)
      CloseHandle(m_handle);
  }

protected:
  static unsigned long WINAPI SadThread(void* param)
  {
    ForeverAlone* thisObject = reinterpret_cast<ForeverAlone*>(param);

    // is there any way for me to access:
    thisObject->m_friends;
  }
};

原始问题:我有一个静态保护线程方法,我将一个对象传递给它.我可以以某种方式让班级朋友本身,以便我可以访问其私人会员?

解决方法

所有类方法(静态或非静态)都是类的“朋友”. Friend用于允许外部函数和类访问类.班级总是自己的“朋友”.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读