<tfoot id='4vPdV'></tfoot>

    <legend id='4vPdV'><style id='4vPdV'><dir id='4vPdV'><q id='4vPdV'></q></dir></style></legend>
    • <bdo id='4vPdV'></bdo><ul id='4vPdV'></ul>

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

      <small id='4vPdV'></small><noframes id='4vPdV'>

        C++.错误:void 不是指向对象的类型

        C++. Error: void is not a pointer-to-object type(C++.错误:void 不是指向对象的类型)
      1. <legend id='jeox3'><style id='jeox3'><dir id='jeox3'><q id='jeox3'></q></dir></style></legend>

          <tfoot id='jeox3'></tfoot>

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

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

              <tbody id='jeox3'></tbody>

                • <bdo id='jeox3'></bdo><ul id='jeox3'></ul>
                  本文介绍了C++.错误:void 不是指向对象的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 C++ 程序:

                  I have a C++ program:

                  struct arguments
                  {
                    int a, b, c;  
                    arguments(): a(3), b(6), c(9) {}
                  };
                  
                  class test_class{
                    public:
                  
                      void *member_func(void *args){
                        arguments vars = (arguments *) (*args); //error: void is not a 
                                                                //pointer-to-object type
                  
                        std::cout << "
                  " << vars.a << "	" << vars.b << "	" << vars.c << "
                  ";
                      }
                  };
                  

                  编译时报错:

                  error: ‘void*’ is not a pointer-to-object type
                  

                  有人可以解释我做错了什么导致这个错误吗?

                  Can someone explain what I am doing wrong to produce this error?

                  推荐答案

                  您在将 void * 转换为具体类型之前取消引用它.你需要反过来做:

                  You are dereferencing the void * before casting it to a concrete type. You need to do it the other way around:

                  arguments vars = *(arguments *) (args);
                  

                  这个顺序很重要,因为编译器不知道如何将 * 应用到 args(这是一个 void * 并且可以' 不会被取消引用).您的 (arguments *) 告诉它该做什么,但为时已晚,因为取消引用已经发生.

                  This order is important, because the compiler doesn't know how to apply * to args (which is a void * and can't be dereferenced). Your (arguments *) tells it what to do, but it's too late, because the dereference has already occurred.

                  这篇关于C++.错误:void 不是指向对象的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Constructor initialization Vs assignment(构造函数初始化 Vs 赋值)
                  Is a `=default` move constructor equivalent to a member-wise move constructor?(`=default` 移动构造函数是否等同于成员移动构造函数?)
                  Has the new C++11 member initialization feature at declaration made initialization lists obsolete?(声明时新的 C++11 成员初始化功能是否使初始化列表过时了?)
                  Order of constructor call in virtual inheritance(虚继承中构造函数调用的顺序)
                  How to use sfinae for selecting constructors?(如何使用 sfinae 选择构造函数?)
                  Initializing a union with a non-trivial constructor(使用非平凡的构造函数初始化联合)
                  • <bdo id='3LTav'></bdo><ul id='3LTav'></ul>

                          <small id='3LTav'></small><noframes id='3LTav'>

                            <tbody id='3LTav'></tbody>
                        1. <tfoot id='3LTav'></tfoot>

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

                            <legend id='3LTav'><style id='3LTav'><dir id='3LTav'><q id='3LTav'></q></dir></style></legend>