0

In my print method, I want to print the name of my Team class ("Bar"). Is there a way to get the name of a class without sending it as an argument? I want to build inside the ostream cout << operator something like "Team name : **function that gets the name ("Bar" in this case) **"

int main ()
{
    cout << "hello"<<endl;
    Team Bar;

    for (int i = 0; i < 2; i++)
    {
        Bar.addPlayer();
    }

    cout << Bar; //here I want to print the name of the Team ("Bar") without having a string Bar as a parameter

    Bar.manage();
    cout << Bar;

    return 0;
}
gbulmer
  • 4,210
  • 18
  • 20
Mooly
  • 11
  • 5

1 Answers1

0

No. This has nothing to do with classes: you cannot print, at runtime, the name of any variable. Those names no longer exist after your code is compiled.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055