C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] How to Restrict Class Methods to specific other classes without invoking friend
From: DBJ (dbj_at_[hidden])
Date: 2021-02-23 02:59:08


https://godbolt.org/z/WYTsxr

On Tue, 23 Feb 2021 at 08:24, Emile Cormier via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Hi Joshua,
>
> Search for "C++ passkey idiom". It may be just what you're looking for.
>
> Cheers,
> Emile Cormier
>
> On Tue, Feb 23, 2021 at 2:34 AM Joshua Brown via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>> Hi,
>>
>> I have a lot of trouble finding anything on stack overflow or elsewhere
>> on this topic. I have been attempting to better encapsulate some of my
>> classes and the scopes in which they can be used. I am trying to find out
>> if there exists a way to limit access of certain methods of a class to
>> another class without using private access modifier with the friend
>> keyword. Adding a class as a friend is overkill and does not really help
>> with improving the encapsulation.
>>
>> One of the use cases I am running into is allowing a constructor to only
>> be called by a few specific classes. Imposing this limitation is beneficial
>> when the classes are large and I do not want to allow arbitrary creation of
>> them.
>>
>> If there is not an easy way to do this, I'm trying to find out if it
>> would be worth starting down the road of making a proposal.
>>
>> Joshua Brown
>>
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>



STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups