[Dev-C++] newbie dynamic_cast question
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <tc...@gm...> - 2002-12-08 06:52:18
|
Hi all,
I have a dynamic_cast problem and I am not comming forward since then in
my project. Therefore I decided too find some help here in ths ML.
OK,
I actually want to implement the iterator design Pattern in order to
iterate through abstract Elements of abstract CollectionObjects.
Therefore I have a class Element and CollectionObject.
Now I have written some concrete implementing classes Directory and File
that are supposed to be both Elements, with the supplement that
Directory is also a CollectionObject.
So I have sth. like
class Element{...}
class FileSystem : public Element { }
class File : public FileSystem {...}
class Directory : public CollectionObject, public FileSystem { ... }
Now I decided to include some Filters, Iteated elements should be
matched by Patterns (abstract class). I have created for this one a
PatternExtension concrete class. It all looks lie this:
class Pattern {
...
public:
virtual bool match( Element *p_Element ) = 0;
}
class PatternExtension : public Pattern
{
...
virtual bool match( Element *p_Element )
{
//here starts the problem:
//writing this instruction is causes an Error from the //compiler.
Therefore I have been looking in my doc.
//and I am convince to be doing it properly....
File *l_File;
if( l_File = dynamic_cast<File *>( p_Element ) != NULL )
{
...
}
/*
Compiler error message:
PatternExtension.cpp:19: cannot dynamic_cast `p_Element' (of type `class
fs::Element *') to type `class fs::File *'
make[1]: *** [PatternExtension.o] Fehler 1
make[1]: Verlassen des Verzeichnisses Verzeichnis
»/work/Projects/C++/Project1/fs«
make: *** [all] Fehler 2
*/
}
}
Why then?
I hope I wasn't too long and that I made myself clear enough. I would be
pleased for any hint, tip to help me comming forward.
Thanx
--
Eric Tchepannou
|