Date: Sat, 15 Aug 2026 19:14:19 +0800
`this A1 const &self` requires that this object must be convertible to
`A1 const &`. Apparently B1 cannot be converted to A1, due to the
private inheritance.
On Fri, 14 Aug 2026 at 21:37, sidneycogdil via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> https://godbolt.org/z/MxacGPbGo
>
> ```cpp
> struct A1 {
> A1(int a)
> : a(a)
> {
> }
>
> auto get(this A1 const &self)
> {
> return self.a;
> }
>
> private:
> int a;
> };
>
> struct B1 : private A1 {
> using A1::get;
> };
>
> auto f(B1 &b)
> {
> auto n = b.get(); // doesn't work. bad
> (void)n;
> }
>
> struct A2 {
> A2(int a)
> : a(a)
> {
> }
>
> auto get() const
> {
> return this->a;
> }
>
> private:
> int a;
> };
>
> struct B2 : private A2 {
> using A2::get;
> };
>
> auto f(B2 &b)
> {
> auto n = b.get(); // works. good
> (void)n;
> }
>
> ```
>
> The only difference is that explicit object parameter is used in A1::get but
> not in A2::get.
>
>
>
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
`A1 const &`. Apparently B1 cannot be converted to A1, due to the
private inheritance.
On Fri, 14 Aug 2026 at 21:37, sidneycogdil via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> https://godbolt.org/z/MxacGPbGo
>
> ```cpp
> struct A1 {
> A1(int a)
> : a(a)
> {
> }
>
> auto get(this A1 const &self)
> {
> return self.a;
> }
>
> private:
> int a;
> };
>
> struct B1 : private A1 {
> using A1::get;
> };
>
> auto f(B1 &b)
> {
> auto n = b.get(); // doesn't work. bad
> (void)n;
> }
>
> struct A2 {
> A2(int a)
> : a(a)
> {
> }
>
> auto get() const
> {
> return this->a;
> }
>
> private:
> int a;
> };
>
> struct B2 : private A2 {
> using A2::get;
> };
>
> auto f(B2 &b)
> {
> auto n = b.get(); // works. good
> (void)n;
> }
>
> ```
>
> The only difference is that explicit object parameter is used in A1::get but
> not in A2::get.
>
>
>
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
-- Yongwei Wu URL: http://wyw.dcweb.cn/
Received on 2026-08-15 11:14:38
