In C++, I'm getting a message “error: 'void*' is not a pointer-to-object type”

后端 未结 3 1929
死守一世寂寞
死守一世寂寞 2021-01-24 09:08

Here\'s my code:

#include 
using namespace std;

int main()
{
   void *x;
   int arr[10];
   x = arr;
   *x = 23; //This is where I get the error         


        
3条回答
  •  不知归路
    2021-01-24 10:06

    you cant derefrence void*, and that is what the coder is doing.

    *x = 23; // this cant be done with void*
    

    instead :

    x = &arr[index] ; // this is correct
    

提交回复
热议问题