C++. Error: void is not a pointer-to-object type

前端 未结 6 1247
一生所求
一生所求 2020-12-06 04:35

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 *arg         


        
6条回答
  •  天涯浪人
    2020-12-06 05:11

    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);
    

    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.

提交回复
热议问题