How do I use heterogeneous lookup with std::queue?

In C++, heterogeneous lookup allows us to access members of a class that can be found in types of different categories, such as base classes. This can be particularly useful when working with standard containers like `std::queue`.

Below is an example that demonstrates how to leverage heterogeneous lookup with `std::queue`. In this example, we have a base class `Base` and a derived class `Derived`. We create a queue of `Derived` objects and access members from both classes.

#include #include class Base { public: void display() { std::cout << "I am Base class" << std::endl; } }; class Derived : public Base { public: void show() { std::cout << "I am Derived class" << std::endl; } }; int main() { std::queue myQueue; Derived d1; myQueue.push(d1); // Accessing Derived class member myQueue.front().show(); // Accessing Base class member myQueue.front().display(); return 0; }

keywords: heterogeneous lookup std::queue C++