0

I'm trying to pass some data between methods.

In one method, I call the other method, passing in an address to store the file status.

grpc::StatusCode ClientNode::Store(const std::string &filename) {
    ....
    FileStatus file_server_status;
    StatusCode statStatusCode = this->Stat(filename, &file_server_status);
    ....
}

In the method that gets called, the paramter is a void*, so it doesn't work because the conversion from void* to FileStatus* is invalid.

grpc::StatusCode ClientNode::Stat(const std::string &filename, void* file_status) {
    ....
    Status status = service_stub->GetFileStatus(&context, request, file_status);
    ....
}
test.cpp:318:79: error: invalid conversion from ‘void*’ to ‘dfs_service::FileStatus*’ [-fpermissive]
     Status status = service_stub->GetFileStatus(&context, request, file_status);

How do I make this work? In C I would just do a cast, but this doesn't seem to be allowed in C++.

bard
  • 2,762
  • 9
  • 35
  • 49
  • Yes, C++ does not have an implicit conversion from `void *` to another pointer type. You must ***explicitly*** cast it, if needed. Do you know how to explicitly cast types, in C or C++ (hint, the same way it's done in C will also work in C++)? – Sam Varshavchik Nov 13 '20 at 13:11
  • Well, technially a c-style cast is allowed, but discouraged. Why is the parameter a `void*` anyway? I would tend towards making the parameter the type you want to have (`dfs_service::FileStatus*`), or a template if needed. – perivesta Nov 13 '20 at 13:12

0 Answers0