Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address_of不能获取对象的真实地址 #133

Closed
zgjsxx opened this issue May 24, 2023 · 5 comments · May be fixed by #139
Closed

address_of不能获取对象的真实地址 #133

zgjsxx opened this issue May 24, 2023 · 5 comments · May be fixed by #139

Comments

@zgjsxx
Copy link

zgjsxx commented May 24, 2023

// 获取对象地址

template <class Tp>
constexpr Tp* address_of(Tp& value) noexcept
{
  return &value;
}

上述代码用于获取对象的真实地址,但是在重载operator&时,上述代码是不work的,下面是我的一个验证:

https://godbolt.org/z/cPd1WMx7h

可能需要使用std::addressof进行修复

@Adeshen
Copy link

Adeshen commented May 24, 2023 via email

@Alinshans
Copy link
Owner

确实是这样,所以标准库是比较复杂的,但我这项目不探究完整的实现,旨在建立一个基本的认识,谢谢你提出的问题

@Adeshen
Copy link

Adeshen commented Oct 7, 2023 via email

@zgjsxx
Copy link
Author

zgjsxx commented Oct 7, 2023

感谢作者回复

@zgjsxx zgjsxx closed this as completed Oct 7, 2023
@frederick-vs-ja
Copy link
Contributor

这个问题不该关,我要修复。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants