This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ARM Compiner c++ error (class, virtual, override)

Hi

When I try to make new class, which inherited from another class I found, as I understand, a mistake in working a compiled code.

Code Example:

char s[1024];

class Parent{
        public:
                Parent(){
                        vMethod();
                };
                virtual void vMethod(){
                        sprintf(s,"Parent virtual method");
                };
};

class Child: Parent{
        public:
                Child(){
                        vMethod();
                };
                virtual void vMethod(){
                        sprintf(s,"Child virtual method");
                };
};

int main(void){

        Child* c = new Child();
...

So, what happends. At this code the methos and constructor calling should to be the next:
1. Calling the Parent constructor, which call overrided vMethod of Child class
2. Calling the Child constructor, which again call overrided vMethod of Child class.

But the Parent construcor calls Parent vMethod and the Child constructor calls Child vMethod. So clasic overriding is works not correct.

The clasic construction on overrided method shoilt to looks like:
override void vMethod(){}
or
virtual void vMethod() override{}
but none of this code construction dosn't work.

So it's a error in compilator or I shoult to use another construction for correct overriding virtual class methods.

Thanks.