Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要访问由 void 指针指向的缓冲区中的对象。该对象位于某个偏移量,但由于禁止对 void 指针进行算术运算,我该如何访问该对象?
char*如果更适合您的需要,您可以将指针转换为(此类指针上的 +1 偏移一个字节)或任何其他指针类型。
char*
但是,这种方法非常容易出错!你最好检查一下你的设计,这里有什么味道!void*在 C++ 中 99% 的情况下是不必要的,使用它们的设计通常比“C++”更“C”。请记住,模板和继承应该是做这些事情的方式。
void*