GSI Forum
GSI Helmholtzzentrum für Schwerionenforschung

Home » PANDA » PandaRoot » Tracking » Smoothing method in class Kalman
inheritance in C++ important question [message #8081 is a reply to message #8079] Mon, 16 March 2009 14:09 Go to previous messageGo to previous message
Anonymous Poster From: 141.39.167*
Hi,

what I stated in my last reply in this thread about virtual in C++ turns out to be true. Please compile and run the following snipplet

//---------------
#include<iostream>

class A{
public:
virtual void doit(){std::cout<<"A"<<std::endl;}
};
class B : public A{
public:
void doit(){std::cout<<"B"<<std::endl;}
};
class C{
public:
void doit(){std::cout<<"C"<<std::endl;}
};
class D : public C{
public:
void doit(){std::cout<<"D"<<std::endl;}
};

int main(){
A* x = new B;
C* y = new D;
x->doit();
y->doit();
((D*)y)->doit();
}
//---------------

It prints
B
C
D
and the compiler gives no warning, also not with -Wall -pedantic. Does anybody know how I can force the compiler to not allow the overwriting at all, like in the case of class D where I (one could mistakenly think) overwrite the method?

Please help a C++ fool!

Cheers, Christian
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Genfit Doxygen Documentation
Next Topic: problem with TrackCand
Goto Forum:
  


Current Time: Thu Apr 25 18:30:14 CEST 2024

Total time taken to generate the page: 0.00901 seconds