Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //complete syntax
- class example{
- T m_what_ever;
- T operator .read_only(){
- return m_what_ever;
- }
- T operator .any_use(const T& value){
- m_what_ever = value;
- return m_what_ever;
- }
- void operator .write_only(const T& value){
- m_what_ever = value;
- }
- //default if both readonly and writeonly are defined
- T operator .any_use_default(const T& value){
- this.operator .any_use_default(const T& value); //call write only
- return this.operator .any_use_default(); //call read only
- }
- }
- 1) READ ONLY VARIABLE
- declaration:
- class exampleReadOnly{
- std::vector blabla;
- std::size_t operator .lenght(){
- return blabla.lenght();
- }
- }
- use:
- exampleReadOnly container;
- std::size_t len = container.lenght; //OK
- container.lenght = 5; //ERROR can't assign to readonly member | operator .lenght can't accept value ...
- 2) WRITE ONLY VARIABLE
- this is not realy usefull but why not...
- declaration:
- class authorizationClient{
- std::string m_password;
- void operator .password(std::string value){
- m_password = value;
- }
- }
- use:
- authorizationClient auth;
- auth.password = "secret"; //OK
- std::string stolenPassword = auth.password; //ERROR can't get value of writeonly member | void can't be converted to std::string ...
- 3) ANY ACCESS
- declaration
- class user_databaseManaged{
- uint id;
- std::string m_sname;
- void operator .sname(std::string value){
- database.updateUserValue(id, "sname", value); //void updateUserValue<T>(uint userId, std::string columnName, T value) throw (databaseError)
- m_sname = value;
- }
- std::string operator .sname() {
- if(loadFromDbRequired){
- return database.getUserValue<std::string>(id, "sname"); //T getUserValue<T>(uint userId, std::string columnName) throw (databaseError, cantCastException)
- } else {
- return m_sname;
- }
- }
- }
- use:
- user_databaseManaged currentUser(currentUserId);
- std::string sname = currentUser.sname; //OK, database getUserValue called as side effect
- currentUser.sname = "Jakub"; //OK, database setUserValue called as side effect
- //loadFromDbRequired = false
- std::string name = currentUser.sname //OK, currentUser.m_sname returned
Advertisement
Add Comment
Please, Sign In to add comment