1 year ago
#367110
glades
Initialize member string with class object name in C++?
Is there a way to instantiate an object and have a string member take the object's name? I would also not mind for a gcc builtin.
Here's an example:
#include <string>
class A
{
std::string obj_name_ = /* set to the objects name (very_descriptive_name) somehow */ ;
};
A very_descriptive_name; // naming the *object* should be enough, do we really have to initialize the string with exactly the same name?
The string is later used for recognisability.
c++
variable-names
class-members
0 Answers
Your Answer