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.
我有一个类重载 & 运算符并将其设为私有。我没有最新的符合 C++11 的编译器,所以有什么方法可以仅使用当前的 C++ 编译器获取对象的地址
谢谢
reinterpret_cast<T *>(&reinterpret_cast<char&>(obj))
不知道它是否安全..(很明显它有点狡猾)
使用addressof()Boost.Utility 中的函数。如果您不想使用 Boost,您仍然可以查看它的实现,它仅包含一个标头。
addressof()