Home Help Center

About Classes as Unions

levellevel Member ✭✭
the .ice file is

class base
{
int d;
};
class stringbase extends base
{
string s;
};
class Hello
{
nonmutating void sayHello(base i);
idempotent void shutdown();
};
....

In the implement file , in the function

void sayHello(base i);
How can I dynamic_cast or static_cast the base pointer to stringbase pointer?

Comments

  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    In C++, you can use the smart pointer dynamicCast method:
       void sayHello(basePtr i)
       {
             stringbasePtr s  = stringbasePtr::dynamicCast(i);
       }
    

    In Java, you can just do a regular dynamic cast:
       void sayHello(base i)
       {
             stringbase s = (stringbase)i;
       }
    

    Benoit.
  • levellevel Member ✭✭
    It's ok
    Thank a lot .
Sign In or Register to comment.