Originally posted by: hans007
so i was asked this at an interview today and did not know the answer.
when you declare pure virtuals in c++
its like say virtual int bob (int x)=0;
if you go like virtual int bob (int x)=9;
or something like that , a number besides 0 what happens?
Originally posted by: itachi
yea, it makes all the difference. c++ handles inheritance through a jump table.. when u include runtime type-info, it uses that table to determine where to jump. the entries in the table are the offsets to the respective methods.
most compilers won't let you make that actual assignment, but if they did it may also think that the address is valid too - so it would probably allow you to instantiate the class, expecting the implementation for the particular method at address 9.
Originally posted by: itachi
yea, it makes all the difference. c++ handles inheritance through a jump table.. when u include runtime type-info, it uses that table to determine where to jump. the entries in the table are the offsets to the respective methods.
most compilers won't let you make that actual assignment, but if they did it may also think that the address is valid too - so it would probably allow you to instantiate the class, expecting the implementation for the particular method at address 9.
not necessarily.. =0 characterizes a pure virtual function, throughout the application no reference can be made to it.. since it doesn't exist. if a reference were to be made without raising any compiler errors, the respective entry would be 0.Originally posted by: smack Down
Originally posted by: itachi
yea, it makes all the difference. c++ handles inheritance through a jump table.. when u include runtime type-info, it uses that table to determine where to jump. the entries in the table are the offsets to the respective methods.
most compilers won't let you make that actual assignment, but if they did it may also think that the address is valid too - so it would probably allow you to instantiate the class, expecting the implementation for the particular method at address 9.
That doesn't make any sense at all. If it was going to use 9 as the address it would have also used 0 as the address.
To know what it would do you need to pay for and read the C++ standard.
Originally posted by: xtknight
What I wonder is why they'd even bother asking a question like that.