class MyClass
def jump
p 'boing!'
end
end
class NewClass < MyClass
end
class ClassWithNoLegs
end
def make_class_jump(klass)
klass.jump if klass.respond_to?(:jump)
end
new = NewClass.new
old = MyClass.new
noleg = ClassWithNoLegs.new
[new, old, noleg].each {|x| make_class_jump x}
module Meh
def make_this_jump
jump if respond_to?(:jump)
end
end
I apologize ahead of time, im gonna be putting up a few posts today, i have a good amount of free time, and there are several questions that have been rolling around in my head.
So i had a questions relating to c++ classes, inheritance, and dlsym.
1) So my first question relates to c++ classes and inheritance. If i understand correctly i can make a class, well call it MY_CLASS for now. I can then create another class called MY_NEW_CLASS and have it inherit the properties and methods of MY_CLASS. This part i follow just fine. My question is, from what i have read is i can pass an instance of MY_NEW_CLASS as a parameter to a function that would normally only accept MY_CLASS because MY_NEW_CLASS inherits from MY_CLASS. Is this correct?
And assuming that is correct. Im also assuming that i can create an instance of a MY_NEW_CLASS and return it from a function that is only expecting a MY_NEW class to be returned.
And assuming all that is correct, assuming when the MY_CLASS variable is returned from a function that was actually passed a MY_NEW_CLASS as long as i cast the returned variable properly to a MY_NEW_CLASS it would still function normally as my new class and not of been pillaged and raped by being returned as a MY_CLASS correct?
I know this may seem a bit basic, but i just want to make sure i grasp the concept before i go writing this huge chunk of code.
2) Now for the second part. Lets say that MY_NEW_CLASS is not part of my original program but still inherits from MY_CLASS. If i load up a shared object into my program that makes use of MY_NEW_CLASS can it still pass MY_NEW_CLASS as a parameter of MY_CLASS to functions, and be returned by functions without mangling since the original program knows nothing of MY_NEW_CLASS?
Thanks in advance.
_-Menser-_