C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Namespace with access specifiers in class interface

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Wed, 9 Nov 2022 19:22:07 +0100
Hi Jim,   a way to not change too much would perhaps be:   class C {   public:     void printi() { cout << "Value: " << i.var << endl; } private:     ProtectedData<int, &C::printi> i; }; With ProtectedData being a template class that creates an private int i.var and is friends with member function C::printi.   Only for friends it provides access to i.var.   Not sure, if you would be happy with such a solution or what would be missing (if at all) to write a ProtectedData template (member function pointers can be template arguments, member functions can be friends, but perhaps both concepts do not work together, as for a friend function you have to specify the declaration, whereas for a class the class name is enough? Perhaps ProtectedData would use an intermediate class).     Best, Sebastian   -----Ursprüngliche Nachricht----- Von:Smith, Jim via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Mo 07.11.2022 21:17 Betreff:[std-proposals] Namespace with access specifiers in class interface An:std-proposals_at_[hidden]; CC:Smith, Jim <jim.smith_at_[hidden]>; Hi, Sometimes I'd like to hide data from a subset of class methods while still allowing other methods to access them. Also it would be helpful to set read/write access on class data for certain methods. Allowing namespaces with access specifiers in class interface would look like this: class Foo {   namespace {     read_write: [Method_1()];         read_only:  [Method_2()];         char data1;     float data2;   };  public:   void Method_1();   void Method_2();   void Method_3();   private: // global to class   int x;   int y; };        -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2022-11-09 18:22:08