This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Class casting


Is there a way to force class casting in g++? Given the code below, some
compilers will automatically cast class B to it's base-class using the
function call in main().  Is there a way to make gcc recognize and/or
force this cast?  Any help would be appreciated.  Than you in advance.


class A{
    public:
    A(){}
    virtual void doStuff()=0;
};
class B : class A{
    public:
    B():A(){}
    void doStuff(){
        std::cout << "Class B";
    }
};
class C{
    public:
    C(A& a) : initialize....{do Stuff;}
    void doOtherStuff(){
        a.doStuff();
    }
};

int main(){
    C* c = new C(B()); 
    c->doOtherStuff();
    return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]