Re: pfType oddness

New Message Reply Date view Thread view Subject view Author view

From: Geoff Levner (g.levner++at++acsys.it)
Date: 02/22/2000 03:13:35


Chris Scharver wrote:

> I'm having some trouble trying to use some Performer type checking.
> I have made a networked pfDCS class called pfNetDCS--a bit of a pain
> since none of the functions in pfDCS are virtual, but that's another
> matter. Anyhow, I have a node obtained through intersection tests.
> I need to cast it as a pfNetDCS if it's of that type, but for some
> reason the test fails.
>
> if (item->isOfType( pfNetDCS::getClassType ))
> {
> ((pfNetDCS *) item)->setMat( newMatrix );
> }
> else
> {
> cout << "It's just a " << item->getClassName() << endl;
> }
>
> When this check runs during execution, I get the line "It's just a
> NetDCS". Well, that's obviously what I expected it to be, so why is
> the correct class name being returned but isOfType is failing its
> check? Any idea what I'm not doing correctly?

For one, add parentheses after getClassType, it's a function call.

Also, be sure you do the following:

1. allocate a new pfType before creating your first pfNetDCS, i.e.:

    pfType *pfNetDCS::classType;
    pfNetDCS::init()
    {
        if (classType == NULL) {
            pfDCS::init();
            classType = new pfType(pfDCS::getClassType(), "pfNetDCS");
        }
    }

2. set the class in your constructor function:

    pfNetDCS::pfNetDCS()
    {
        setType(classType);
    }

--
Geoff Levner -- g.levner++at++acsys.it
ACS Studio, via Aurelia 58, 00165 Roma, Italy
tel. +39-063936331, fax +39-0639363317


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Tue Feb 22 2000 - 03:09:42 PST

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.