IonicWind Software

Aurora Compiler => General Discussion => Topic started by: J B Wood (Zumwalt) on September 05, 2006, 08:12:37 PM

Title: class inheritance
Post by: J B Wood (Zumwalt) on September 05, 2006, 08:12:37 PM
How do you inherit a class in a class?

myclass: subclass

???

right now all we have to my knowledge is

myclass :: myclass()
{
}

would it be
myclass :: myclass() : subclass
??
Title: Re: class inheritance
Post by: Parker on September 05, 2006, 08:23:01 PM
class First
{
    declare First( ) { print( "First::First( )" ); }
    declare virtual Stuff( ) { print( "First::Stuff( )" ); }
}

class Second : First
{
    declare Second( ) { print( "Second::Second( )" ); }
    declare virtual Stuff( ) { print( "Second::Stuff( )" ); }
}

global sub main( )
{
    First *c = new( First, 1 );
    c->Stuff( );
    delete c;
    print( "----" );
    c = new( Second, 1 );
    c->Stuff( );
    delete c;
}


Alternatively

//...
class Second : First
{
    declare Second( );
    declare virtual Stuff( );
}

Second::Second( )
{
    print( "Second::Second" );
}

Second::Stuff( )
{
    print( "Second::Stuff" );
}
//...


What exactly do you mean by "inherit a class in a class"? What I've shown is the only way things work in all OOP languages (except multiple inheritance and interfaces, but I'm pretty sure that's not what you're talking about).
Title: Re: class inheritance
Post by: Ionic Wind Support Team on September 05, 2006, 08:23:50 PM
You inherit a class in the defintion, not the implementation, just as you do in C++

class myclass : CWindow
{
}

But I have the feeling your asking something else.  If yoru refering to virtual funcitons that is handled automatically, if yoru class is derived from CWindow you can call any method that exists in CWindow. 

What is it you're asking?

[Edit] parker beat me to it.  Must be getting slow.
Title: Re: class inheritance
Post by: J B Wood (Zumwalt) on September 05, 2006, 08:24:13 PM
Thanks next question.


dMatrix &matrix

What is its equivelent for the &matrix?

Parkers answer was snap on what I needed for the first question, not viruals.
thanks :)
Title: Re: class inheritance
Post by: Parker on September 05, 2006, 08:25:41 PM
That's a reference. You can use a pointer and make sure you dereference it each time you use it.
C++:
SomeClass &c = ...;
c.doStuff( );


Aurora:
SomeClass *c = ...;
c->doStuff( );
Title: Re: class inheritance
Post by: J B Wood (Zumwalt) on September 05, 2006, 08:28:14 PM
Thanks parker, don't beat on me to hard guys, I have had a long day trying to get the Newton thing working.
Now I am converting headers to test the main newton.inc I created, since I know I tested most of the initial stuff just by calling it to see if it broke and it didn't.
Now I want to make it work, so running into these little roadblocks during translation.
Just trying to help.
Title: Re: class inheritance
Post by: J B Wood (Zumwalt) on September 05, 2006, 08:35:30 PM
This has been killing me all day...

What is

unsigned


in aurora?


nevermind, its an unsigned INT
or int64 in aurora I guess..
Title: Re: class inheritance
Post by: J B Wood (Zumwalt) on September 05, 2006, 08:43:33 PM
Also here is another one, in a definition how do I assign a default?
For instance:

RenderPrimitive :: RenderPrimitive(dSceneNode *parent, dMatrix *matrix, int texture = -1)
{
}


This is obvsiouly in my SRC file.
Title: Re: class inheritance
Post by: Ionic Wind Support Team on September 05, 2006, 09:01:39 PM
Has to be in the declare, just use the 'opt' keyword.

declare  RenderPrimitive(dSceneNode *parent, dMatrix *matrix, opt int texture = -1);

RenderPrimitive :: RenderPrimitive(dSceneNode *parent, dMatrix *matrix, opt int texture = -1)
{
}
Title: Re: class inheritance
Post by: J B Wood (Zumwalt) on September 05, 2006, 09:32:15 PM
Thanks, going to add 2 more files over on the Newton discussion.