Q: So I was asked this during an interview today and did not know that you explain answer.
when pure virtual in C + 977 503 977 503 to say her virtual int bob (int x) = 0;
if proceed as virtual int bob (int x) = 9;
or something like that, besides a number 0 what happens?
Best Answer: Any function/method with the same signature gets overridden by the latest class' definition:
class A – method … doA()
class B : A – method … doA()
class C : B – method … doA()
object of class C will execute class C definition of doA()…
http://www.dgp.toronto.edu/~jstewart/270…
Wildlife Stock Photos on Virtual Cd
Re:You get an error. I just tried it. Here is the error.
error C2258: illegal pure syntax, must be '= 0'
Virtual Pose
Re:Originally posted by: guy
What I wonder is why they'd even bother asking a question like that.
because at the big name software company i work for, they ask crap like that in sad attempts by hans to transfer to another group with a promotion.
needless to say i did not get the promotion though they offered to let me transfer at current pay and with the promise that the work would be "exciting". i then heard from a friend in that group that it just meant there were 15 more hours of it.
haha.
yeah, but yeah… the interviewer was some indian dude with a masters. he just kept asking questions, and if you got it right, ask even a deeper more obscure ridiculous trivia. and kept asking "are you sure?", in some ploy to get me flustered i guess. lets jsut say at that point with the =0 or =9 i was totally stumped.
Virtual Pet Business
Re:Originally posted by: guy
Originally posted by: guy
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.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.
Tienda Virtual En Casa
Re:Originally posted by: guy
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.
Freelance From Home As A Virtual Assistant
Re:What I wonder is why they'd even bother asking a question like that.
1 Virtual "Work At Home" Career for 2009
Re:I would think that = 0 is just a way of saying "pure virtual" and doesn't really have any other literal meanings (ie there's no real assignment going on). So = 9 would be invalid and would give an error.
Outsouring and using a Virtual Assistant for Fun and Proft
Re:Originally posted by: guy
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.
ah thanks man that makes a lot of sense. i wa swondering because i was not sure whether all compilers would have the error at all error levels.
Virtual Tour Show Software – Recurring Billing
Re: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.
Virtual Private Server (vps) with Web Interface, for MetaTrader Forex
Re:compiler error like was mentioned before
Virtual Worlds: Past, Present and Future
Re:um yeah i think you guys are not understanding what i asked. i dont need an explanation of what a pure virtual IS, or what an abstract class is. i know all that stuff.
what i know is t a virtual to be pure has to have =0; that doesnt mean the function is =0 it seems to just be the notation for pure virtual.
but the interviewer asked me what if you put =9 or another number. does it make a difference?
and i honestly did not know.. i just used to always assume =0 meant more or less "equal null"
Re:Making a function member of a class virtual means that a derived class may redefine that function. Making it pure virtual means that a derived class must redefine it – at least if you want to instantiate members of that class.
A pure virtual function makes its class an abstract base class – you can't create objects of that type. An abstract base class is often used to define a common API for a class hierarchy. A typical example is an abstract base class called Shape. Various classes could inherit from Shape such as Circle, Square, Trangle, etc.
If you put a pure virtual function called area in shape, then every derived class must implement the area function with the formula appropriate to that sub class. So, as a downstream user, you know that if you are using a class derived from Shape, it must have an appropriate area function.
edit – I obviously can't read this a.m.
I tried it on one of my classes and got the following compiler error with the Gnu compiler:
In file included from point.cc:7:
point.h:327: error: invalid initializer for virtual method `virtual void
Point::Propagate(double)'
Re:pure virtual function is abstract.. can't assign value to it
Re:Free e-books by Bruce Eckel (http://mindview.net/Books/TICPP/ThinkingInCPP2e.html)
Re:Originally posted by: guy
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?
You get an error.
Any in function in the base class that has virtual in front of it can be overridden in the inheriting classes. You must provide functionality in the base class.
In a pure virtual class (has at lease one pure virtual function)you do not provide functionality in the pure virtual function of the base class. You cannot create an instance of the base class, but you can create a pointer to the base class so you can handle mixed inherited classes.
Re:I'm not sure. Compiler error?
0 Comments.