[SOLVED] Can we access a class attribute by the class name in C++?
I am currently working on something which requires extensive use of string manipulation. So I thought of writing my own library for strings (main aim was to mould the in-built functions of the string class to my needs). So this question arose in my mind that can we access an attribute of a class using the class name itself. For example, in my class (called String), I have a public member called str (of type std::string). So suppose that a variable of the defined type String is declared. I want String new_string = name_of_old_string_variable; //operator= is already defined To be compiled as String new_string = name_of_old_string_variable.str; I know that I'm not good with words, so you can check out the code for better understanding of what I want to do. https://code.sololearn.com/cxqUAE1EJVea/?ref=app