Question: I'm using the ASP.NET Boilerplate framework to send mail notification. I want to change the sender mail address based on the scenarios(one for Employees and another one for End Users)

Please advise me how to change sender mail address at run time (other than from default configuration).

```
mailSender.SendAsync(
  to: toEmailAddress,
  subject: mailSubject,
  body: mailBody,
  isBodyHtml: true);

```

Thanks in advance.

Answer: 
There is no built in way in C++ to use a string to look up a variable of the same name in C++.

What you have to do is create the appropriate data structure for yourself. One way to do that would be to use a `map`.

```
#include <map>

std::map<std::string, Enemy> my_map;
...
Enemy trump("Trump", 250, 30);
my_map["Trump"] = trump;
...
std::string name = ...;
Enemy some_enemy = my_map[name];

```
You can store all the instances by name as a static data member in a map for example. But there should be better ways to do it depending on the complete design of your program. But since you didn't provide all the context I'm just going to show a generic example. With some issues like non thread safety, missing null checks, not dealing with duplicates, etc.

```
#include <iostream>
#include <string>
#include <map>
using namespace std;

class Enemy{
    public:
    std::string m_name;
    int m_hp;
    int m_dmg;
    static std::map<std::string,Enemy*> s_instances;

    Enemy(const std::string& name, int hp, int dmg)
    : m_name(name),
      m_hp(hp),
      m_dmg(dmg)
    {
        s_instances[name] = this;
    }
    ~Enemy()
    {
        s_instances.erase(m_name);
    }

    const std::string& getName() const
    {
        return m_name;
    }
    static Enemy* getInstanceByName(const std::string& name)
    {
        Enemy* result = nullptr;
        auto iter = s_instances.find(name);
        if(iter!=s_instances.end()) result = iter->second;
        return result;
    }

};

std::map<std::string,Enemy*> Enemy::s_instances;

void doStuff()
{
    Enemy* instance = Enemy::getInstanceByName("Ork");
    std::cout << instance->getName();
}

int main() {
    Enemy ork("Ork",300,20);
    doStuff();
    return 0;
}

```