Is is possible to use the name of a variable in the constructor?

Eljay Love-Jensen eljay@adobe.com
Mon Aug 1 11:29:00 GMT 2005


Hi Gunther,

The easiest way to implement your desired functionality is to make "passing
in the varname" a parameter, and by convention pass in the varname.

----------------------------------------------------------------
#include <iostream>
#include <string>

using std::cout;
using std::endl;

struct uniform {
  uniform(std::string const& prettyVarname) {
    cout << "A variable called \x1B[32m"
      << prettyVarname
      << "\x1B[0m was just instantiated (sp)"
      << endl;
    }
};

void main() {
    uniform blah("blah");
}
----------------------------------------------------------------

HTH,
--Eljay




More information about the Gcc-help mailing list