<legend id='JXDnY'><style id='JXDnY'><dir id='JXDnY'><q id='JXDnY'></q></dir></style></legend>

    • <bdo id='JXDnY'></bdo><ul id='JXDnY'></ul>
      <tfoot id='JXDnY'></tfoot>
    1. <i id='JXDnY'><tr id='JXDnY'><dt id='JXDnY'><q id='JXDnY'><span id='JXDnY'><b id='JXDnY'><form id='JXDnY'><ins id='JXDnY'></ins><ul id='JXDnY'></ul><sub id='JXDnY'></sub></form><legend id='JXDnY'></legend><bdo id='JXDnY'><pre id='JXDnY'><center id='JXDnY'></center></pre></bdo></b><th id='JXDnY'></th></span></q></dt></tr></i><div id='JXDnY'><tfoot id='JXDnY'></tfoot><dl id='JXDnY'><fieldset id='JXDnY'></fieldset></dl></div>

      <small id='JXDnY'></small><noframes id='JXDnY'>

      1. 如何在 C++ 和 openGL 中将类方法作为另一个函数的

        时间:2023-09-17

            <small id='bEGDJ'></small><noframes id='bEGDJ'>

              <tbody id='bEGDJ'></tbody>
          • <i id='bEGDJ'><tr id='bEGDJ'><dt id='bEGDJ'><q id='bEGDJ'><span id='bEGDJ'><b id='bEGDJ'><form id='bEGDJ'><ins id='bEGDJ'></ins><ul id='bEGDJ'></ul><sub id='bEGDJ'></sub></form><legend id='bEGDJ'></legend><bdo id='bEGDJ'><pre id='bEGDJ'><center id='bEGDJ'></center></pre></bdo></b><th id='bEGDJ'></th></span></q></dt></tr></i><div id='bEGDJ'><tfoot id='bEGDJ'></tfoot><dl id='bEGDJ'><fieldset id='bEGDJ'></fieldset></dl></div>
              <bdo id='bEGDJ'></bdo><ul id='bEGDJ'></ul>

                <tfoot id='bEGDJ'></tfoot>
                <legend id='bEGDJ'><style id='bEGDJ'><dir id='bEGDJ'><q id='bEGDJ'></q></dir></style></legend>
                1. 本文介绍了如何在 C++ 和 openGL 中将类方法作为另一个函数的参数传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我知道这东西有效:

                  void myDisplay()
                  {
                  ...
                  }
                  int main()
                  {
                  ...
                  glutDisplayFunc(myDisplay)
                  ...
                  }
                  

                  所以我尝试将 myDisplay() 函数包含到我创建的类中.因为我想将来用不同的类重载它.但是,编译器抱怨

                  so I tried to include myDisplay() function to a class that I made. Because I want to overload it in the future with a different class. However, the compiler complains that

                  'void (ClassBlah::)()' 类型的参数与 'void(*)()' 不匹配.

                  这是我尝试制作的内容:

                  Here is the what I try to make:

                  class ClassBlah
                  {
                     ....
                     void myDisplay()
                     ....
                  }
                  ......
                  int main()
                  {
                  
                      ...
                      ClassBlah blah
                      glutDisplayFunc(blah.myDisplay)
                      ...
                  }
                  

                  有人知道如何解决这个问题吗?非常感谢.

                  Does anybody knows how to fix this problem? Many thanks.

                  推荐答案

                  首先,在非静态成员函数中有一个隐式的this"指针,所以你需要改变你的void myDisplay()<ClassBlah 中的/code> 是静态的.解决这个限制很尴尬,这就是为什么 C++ faq lite 说 不要这样做

                  Firstly, there is an implicit "this" pointer in non-static member functions, so you'll need to change your void myDisplay() in ClassBlah to be static. It's awkward to work around this limitation, which is why the C++ faq lite says don't do it

                  然后,您应该可以将函数作为 ClassBlah::myDisplay 传递.

                  Then, you should be able to pass the functions as ClassBlah::myDisplay.

                  根据您重载的动机(即您是要在运行时热交换进出实现,还是仅在编译时?)您可能会考虑一个实用程序处理程序"静态类,其中包含指向您的基类的指针,并且通过这种方式委派责任.

                  Depending on your motivation for overloading (ie are you going to hotswap implementations in and out at runtime, or only at compile time?) you might consider a utility "handler" static class that contains a pointer to your base class, and delegates responsibility through that.

                  这篇关于如何在 C++ 和 openGL 中将类方法作为另一个函数的参数传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                    <tbody id='PDEtQ'></tbody>
                  • <legend id='PDEtQ'><style id='PDEtQ'><dir id='PDEtQ'><q id='PDEtQ'></q></dir></style></legend>
                      <bdo id='PDEtQ'></bdo><ul id='PDEtQ'></ul>
                      1. <small id='PDEtQ'></small><noframes id='PDEtQ'>

                        <tfoot id='PDEtQ'></tfoot>

                          <i id='PDEtQ'><tr id='PDEtQ'><dt id='PDEtQ'><q id='PDEtQ'><span id='PDEtQ'><b id='PDEtQ'><form id='PDEtQ'><ins id='PDEtQ'></ins><ul id='PDEtQ'></ul><sub id='PDEtQ'></sub></form><legend id='PDEtQ'></legend><bdo id='PDEtQ'><pre id='PDEtQ'><center id='PDEtQ'></center></pre></bdo></b><th id='PDEtQ'></th></span></q></dt></tr></i><div id='PDEtQ'><tfoot id='PDEtQ'></tfoot><dl id='PDEtQ'><fieldset id='PDEtQ'></fieldset></dl></div>