2015-01-15 11:29:03

Hello audio gamers (and developers),
I have recently been experimenting with BGT, but I’ve ran into the following issue:
If I define a function within a class, such as:
Class object
{
Void example () {
// some code goes here.
}
}
Then I want that same function (but modified):
Class wheel: object
{
Void example() {
// old code
// new code.
}
}
I guess my question is:
Is there a way to include the code from the function in the top class without having to copy it? Just like if you use the super() function within a constructor? Super doesn’t seem to work in this case.
Thanks in advanced for any help.

2015-01-15 14:00:31

You could use something like this:

class wheel : object
{
void example()
{
object::example();
//New code.
}
}

hth

2015-01-15 14:20:34

superantoha wrote:

You could use something like this:

class wheel : object
{
void example()
{
object::example();
//New code.
}
}

hth

Thanks a lot!
I never thought of that. That has saved me in many ways...

2015-01-16 17:36:08 (edited by Ethin 2015-01-16 17:40:33)

Hi,
If you were coding in C++, you could also use a function overload, like this:
namespace example
{
class object
{
void example ()
{
// code
}
}
class wheel : object
{
void example (int a)
{
obj.example();
// new code
}
}
}
// then, get the namespace:
using namespace example;
int main ()
{
object obj = new object;
obj.example(); // call object.example()
wheel wh = new wheel;
int a = 3581;
int b = wh.example(a);
return 0;
}
Of course, BGT doesn't support this, so you wouldn't be able to do that.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2015-01-16 19:33:33

First, I'm not sure why C++ is even coming up.  This is off topic.  But please don't do that in real code, at least not for this reason.  The approach in C++ that matches this kind of thing is to make the function virtual and to use the exact same syntax as in post 2.  If you go down the road of stacking overloads like this, the code becomes nearly impossible to reason about: any subclass ends up having four or five variations on the function and the only way to know all of them is to be familiar with all the classes at the same time.  This approach also steps on some of the horribly dark corners of C++; it works, yes, but raises all sorts of questions about overriding virtual functions in further derived classes for which I'd probably need to go consult my copy of the standard.
Also, that code won't compile.  If you want to actually do it this way, you need to use example(), not obj.example().

My Blog
Twitter: @ajhicks1992

2015-01-17 13:56:49

Ethin wrote:

Of course, BGT doesn't support this, so you wouldn't be able to do that.

This is obviously not helpful to the topic at hand, then, is it?
I don't see how this is remotely relevant, other than trying to show off knowledge. We need a thumbs down button. Plus, the question has already been answered right? tongue

--
Talon
Wanna play my Games? Listen to my Music? Follow me on Twitter, and say hi~
Code is poetry.

2015-01-17 16:39:07

Hi, I have a question, would object.wheel(); be different than object::wheel();? Or do they do the same thing?

2015-01-17 20:07:48

We use dot for instances, i.e. because object is a variable of a type which has a wheel method we want to call.  We use :: for base classes, i.e. because object is our base class and we wish to call its default behaviors for doing whatever wheel does.
They are not interchangeable to my knowledge, but it's possible BGT lets you.

My Blog
Twitter: @ajhicks1992

2015-01-18 20:14:55

Hi,
I'm sorry about that. At least, I'm sorry about post 4.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2015-01-19 17:49:21

no, I don't think you can interchange the . and the :: in bgt.

I like to sleep, Sleep is good,
This is how I do it: Lie on a nice warm cozy bed, and dream dreams about how to rule the world!
Follow @TheGreatAthlon5 on twitter for humorous facts and game updates!
If you like my posts, thumb me up!