Hi!
Ok, I just check documentation, it seems you can't use a dynamic cast
in your case because File is not a base type for Element (of course,
since Element is a base class for File :)
So maybe you should use static_cast, or directly a standard C cast
(personnaly, I found all the cast operator useless, even if it's more
safe, it's too boring too use them :) and I never got a problem with
cast, bugs are generally elsewhere :)
I can give you a good documentation, but it's in french, so if you can
read french, here it is:
http://www.developpez.com/c/megacours/x4009.html#AEN4058
Happy coding,
Sebastien.
On Sun, Dec 08, 2002 at 07:51:09AM +0100, tc...@gm... wrote:
> Hi all,
>=20
> I have a dynamic_cast problem and I am not comming forward since then i=
n=20
> my project. Therefore I decided too find some help here in ths ML.
>=20
> OK,
>=20
> I actually want to implement the iterator design Pattern in order to=20
> iterate through abstract Elements of abstract CollectionObjects.=20
> Therefore I have a class Element and CollectionObject.
>=20
> Now I have written some concrete implementing classes Directory and Fil=
e=20
> that are supposed to be both Elements, with the supplement that=20
> Directory is also a CollectionObject.
>=20
> So I have sth. like
>=20
> class Element{...}
>=20
> class FileSystem : public Element { }
>=20
> class File : public FileSystem {...}
>=20
> class Directory : public CollectionObject, public FileSystem { ... }
>=20
> Now I decided to include some Filters, Iteated elements should be=20
> matched by Patterns (abstract class). I have created for this one a=20
> PatternExtension concrete class. It all looks lie this:
>=20
> class Pattern {
> ...
> public:
> virtual bool match( Element *p_Element ) =3D 0;
> }
>=20
>=20
> class PatternExtension : public Pattern
> {
> ...
> virtual bool match( Element *p_Element )
> {
> //here starts the problem:
> //writing this instruction is causes an Error from the =20
> //compiler. Therefore I have been looking in my doc.
> //and I am convince to be doing it properly....
>=20
> File *l_File;
>=20
> if( l_File =3D dynamic_cast<File *>( p_Element ) !=3D NULL )
> {
> ...
> }
> /*
> Compiler error message:
>=20
> PatternExtension.cpp:19: cannot dynamic_cast `p_Element' (of type `clas=
s=20
> fs::Element *') to type `class fs::File *'
> make[1]: *** [PatternExtension.o] Fehler 1
> make[1]: Verlassen des Verzeichnisses Verzeichnis=20
> =BB/work/Projects/C++/Project1/fs=AB
> make: *** [all] Fehler 2
> */
> }
> }
>=20
> Why then?
>=20
> I hope I wasn't too long and that I made myself clear enough. I would b=
e=20
> pleased for any hint, tip to help me comming forward.
>=20
> Thanx
>=20
> --
> Eric Tchepannou
>=20
>=20
>=20
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>=20
--=20
Time remaining: 29 weeks 1 days 2 hours 17 minutes
|