#include <map>
#include <vector>
#include <iostream>

// Forward declarations needed for defining the global functions.
class typeX;
class typeY;

// Global functions with call by pointer (or reference) to avoid copying objects.
void func(const typeX*) { std::cout << "::func(const typeX&)" << std::endl; }
void func(const typeY*) { std::cout << "::func(const typeY&)" << std::endl; }

// Abstract base class.
class Base {
public:
    virtual void func() = 0;
};

void Base::func() {};

// Derived class as replacement for your original typeX.
class typeX : public Base {
public:
    void func() { std::cout << "typeX::func()" << std::endl; ::func(this); };
    int i;  // Example for your original 'typeX' content.
};

// Derived class as replacement for your original typeY.
class typeY : public Base {
public:
    void func() { std::cout << "typeY::func()" << std::endl; ::func(this); };
    std::string s;  // Example for your original 'typeY' content.
};

int main() {
    typeX A, B;
    typeY Z, Y;

    std::map<std::string, Base*> map;
    map["a"] = &A;
    map["z"] = &Z;
    
    std::vector<std::string> list { "a", "z" };
    for (auto const &list_item : list)
        map[list_item]->func();

	return 0;
}