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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux