Ich möchte meinen Objektnamen als Zeichenfolge speichern. Darf ich erklären, ein paar Zeilen Code zu verwenden.So speichern Sie einen Objektnamen als Zeichenfolge
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
class Example
{
public:
string object_name;
//code...
};
int main()
{
Example object;
cout<<object.object_name<<endl; //In this case the output should be "object", how to achieve this ?
return 0;
}
Sie setzen es mit: 'object.object_name =" object ";' - Ich bin mir ziemlich sicher, das ist nicht die Antwort, die Sie wollten, aber C++ hat diese Art der Reflexion/Introspektion nicht. –
Mögliches Duplikat von [get C++ - Objektname zur Laufzeit] (http://stackoverflow.com/questions/468956/get-c-object-name-in-runtime) –
Vielleicht ein Blick auf [C++ reflexion] (http://stackoverflow.com/questions/41453/how-can-i-add-reflection-to-ac-application) – steiner