October 30, 2025, 02:17:24 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


class inheritance

Started by J B Wood (Zumwalt), September 05, 2006, 08:12:37 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

J B Wood (Zumwalt)

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
??

Parker

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).

Ionic Wind Support Team

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.
Ionic Wind Support Team

J B Wood (Zumwalt)

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 :)

Parker

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( );

J B Wood (Zumwalt)

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.

J B Wood (Zumwalt)

September 05, 2006, 08:35:30 PM #6 Last Edit: September 05, 2006, 08:50:09 PM by zumwalt
This has been killing me all day...

What is

unsigned


in aurora?


nevermind, its an unsigned INT
or int64 in aurora I guess..

J B Wood (Zumwalt)

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.

Ionic Wind Support Team

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)
{
}
Ionic Wind Support Team

J B Wood (Zumwalt)

Thanks, going to add 2 more files over on the Newton discussion.