I don't think i know enough C++ to solve the following problem:
I call a class:
States eiStates(coef1,space);
this class outputs into a txt file.
is there anyway for that file to have the same name as the class + ".dat" extension: "eiStates.dat"?
so this class will output eiStates.dat
and after i call another class
States uStates(coef2,space);
i would like that class to automatically output uStates.dat
If I understand OP correctly.... you want to have the name of the object not the name of the class.
ie:
1 2 3
MyClass foo;
// you want "foo.dat"
// not "MyClass.dat"
In which case, R0mai is correct. There's no way to get the name of the variable at runtime because variable names don't exist at runtime -- they're just there to make writing code easier, but they typically don't exist in the executable (except for debugging purposes, but nevermind that).
The only solution I see to this problem is to record the name of the object in the object itself:
Is putting the variable in a macro really any easier than just putting it in quotes?
Besides... I just assumed he wouldn't have the name of the variable at the time (like he's doing it via pointer/reference in another function or something).