Here some very simple code for me to use in order to demonstrate my question below:
class myClass {
// class constructors
declare _myClass();
declare myClass();
// member functions
declare virtual getValue(),string;
declare virtual setValue(string theString);
// private member variables
string m_value;
}
myClass :: getValue (), string
{
return m_value;
}
myClass :: setValue (string theString)
{
m_value = theString;
print("--- A value was set in myClass through the method 'setValue'");
}
myClass :: myClass()
{
m_value = "--- SIMPLE DEFAULT VALUE";
}
myClass :: _myClass()
{
print("myClass is being destroyed!!");
}
class mySecondClass : myClass
{
declare virtual getValue(),string;
declare virtual setValue(string theString);
}
mySecondClass :: getValue(), string
{
return m_value;
// How would I call the class I am inheriting from here?
}
mySecondClass :: setValue(string theString)
{
m_value = theString;
// How would I call the class I am inheriting from here?
}
global sub main( )
{
// Create instances of the two classes
myClass objClass;
mySecondClass objClass2;
// This outputs the default value
print(objClass.getValue());
// Now I set the value plus this function will print a message to the screen
objClass.setValue("This is the value I put into objClass");
// Now I print the new value
print(objClass.getValue());
// Add one blank lines
print("\n");
// Now for the second class the inherits the first I show the default value
print(objClass2.getValue());
// Now I set a value in the second class
objClass2.setValue("This is the value I put into objClass 2");
// Now I print the new value out
print(objClass2.getValue());
// Wait until the user presses a key
waitForKey();
}
sub waitForKey()
{
ÂÃ, Ã‚Ã, print("\n\npress a key to close");
ÂÃ, Ã‚Ã, While GetKey() = "";ÂÃ, Ã‚Ã,Â
}
In mySecondClass I declare setValue as virtual but I would like to execute some code in mySecondClass and then call the inherited class's (myClass) setValue function as well?ÂÃ, How would I do that?ÂÃ, And if I can, would it affect my member variable m_value in mySecondClass?
Sorry, I couldn't think of better example code to illustrate my point and hopefully my question doesn't sound too confusing.
baseclass!!method. For example,
class Base
{
declare virtual m() { print( "Base::m" ); }
}
class Derived : Base
{
declare virtual m( ) { print( "Derived::m" ); Base!!m( ); }
}
sub main( )
{
Derived d;
d.m( ); // Prints "Derived::m" <newline> "Base::m"
}
Oh, okay. Thanks Parker!
Now, that pretty much just creates a new instance of the Base class which wouldn't affect my member variables.ÂÃ, I was hoping I could use the inherited class's methods and properties as though they were also members of the Derived class (so the function calls directly affect internal variables.) Kind of like I can just expand on a derived class's functions with additional code.
Hmm? You mean, the Base method will affect the member variables? It will, or at least it should. You're not creating a new Base class, it passes the same this pointer, but just calls a different method.
All right, I see it now. *slaps self on forhead* :D
BTW, thanks Parker, that's what I was looking for. :)
Sure, no problem.