Q:

c++ Is a class derived from a specific class?

Is it possible what I'm trying to achieve. This is the problem:
class Content{};

class Content1 : public Content{};
class Content1_1 : public Content1{};
class Content1_2 : public Content1{};

class Content2 : public Content{};
class Content2_1 : public Content2{};
class Content2_2 : public Content2{};

class Container{
public:
    Content* c;
};

Is it possible to determine if the pointer of the Container class points to an object of Content1 or an object of a class derived from Content1?
Thanks.
EDIT:
If I look up the type of the pointer in the container class, it is treated as a content type, though it might actually be a content1 or content2 type, so dynamic_cast doesn't work.
class content{};
class content1 : public content{};
class content2 : public content{};

class container{
public:
    content* c;
};

int main(void)
{
    container* x = new container;
    x->c = new content2;

    if( dynamic_cast<content1*>((content1*)x->c) == NULL){
        //This doesn't fail, eventhough 'content1' and 'content2' shouldn't be compatible.
        //This means that every class, derived from 'content' will be treated as 'content1' when using dynamic_cast.
    }

    return 0;
}

A:

If your types are polymorphic (i.e. if they have at least one virtual function), you can use dynamic_cast<>. The result of dynamic_cast<> will be a null pointer (i.e. nullptr for C++11, NULL for C++03) in case the pointed object is not actually an instance of the specified class, or of a derived class thereof:
Container cont;
Content1* pContent1 = dynamic_cast<Content1*>(cont.c);
if (pContent1 != nullptr)
{
     // cont.c points to an instance of Content1 
     // or a class derived from Content1
}

A common practice is to make the destructor of your base class virtual, so that objects of a class derived from your base class can be deleted through a base class pointer (if the destructor is not virtual, attempting to do so results in undefined behavior):
class Content //Abstract.
{
public:
    virtual ~Content() { }
//  ^^^^^^^
};

