Question: In the below function, while loop condition has 2 statements/expressions "x in my\_string" and "for x in brackets", by what logic both can be mentioned together?

```
def check(my_string): 
    brackets = ['()', '{}', '[]'] 
    while any(x in my_string for x in brackets):# How can 2 statements be mentioned
        for br in brackets: 
            my_string = my_string.replace(br, '') 
    return not my_string 

```

Answer: 
The typename keyword can only be part of a template declaration.

```
template <typename T> class Concept{
public:
    virtual void push(T val) = 0;
    virtual T pop() = 0;
};

```

You have mixed in your mind templates and pure virtual functions. The first is *compile time*, the second is *run time*.

Templates allow you to avoid duplicating code for different data types, where pure virtual member functions allow you to use different polymorphic interfaces that inherit from the same type. [Type erasure](https://akrzemi1.wordpress.com/2013/11/18/type-erasure-part-i/) has also nothing to do with virtual member functions. Two completely different things.

Once the above template is instantiated with, say, `int`, then it is equal to this:

```
   class Concept{
    public:
        virtual void push(int val) = 0;
        virtual int pop() = 0;
    };

```

Now this class is *abstract*; you cannot instantiate it, but you can inherit:

```
class f1 : public Concept {
    public:
    virtual void push(int val) { ... define it }
    virtual int pop()  { ... define it}
};

class f2 : public Concept {
    public:
    virtual void push(int val) { ... define it }
    virtual int pop()  { ... define it}
    ... more members
};

```

And use it polymorphically:

```
Concept* a = new f1();
Concept* b = new f2();

// dynamic_cast<f1>(a) will return a f1*
// dynamic_cast<f2>(b) will return a f2*

```
I don't think you really want to have an interface with an indefinite number of the push and pop methods with different arguments. I also don't think you want to have a number of different implementations of the Concept descendants and a separate stack for each type.
It seems you want to push to the stack objects of different types and then pop them. In this case, it could be something like this:

```
struct Container 
{
    template<typename T>
    Container(T t);
    template<typename U>
    U cast();
};

class Stack
{
public:
    virtual void push(Container val) = 0;
    virtual Container pop() = 0;
};

class ConcreteStack : public Stack
{
public:
    void push(Container val);
    Container pop();
};

int main() 
{
    ConcreteStack stack;
    stack.push(25);
    stack.push(std::string("abcd"));

    std::string str = stack.pop().cast<std::string>();
    int num = stack.pop().cast<int>();
}

```

Unfortunetly, I don't see the way to escape explicit type casting when pop. There couldn't be few methods with the same name that differ only in returning types.