Inherting Classes
Author |
Message |
illu45
![](http://img9.exs.cx/img9/1348/roadavvy2ht.png)
|
Posted: Sat Mar 05, 2005 10:39 pm Post subject: Inherting Classes |
|
|
Hello all,
I am having some trouble with classes and inheritance... I have a clas (let's call it 'basic'), and it is located in a file (say basic.t). I then want to inherit this class in another file (say main.t), however, when I try to do so, I get errors with it not being in main.t's scope, or declaration errors...
Does anyone have some advice on how I would go about ibheriting basic in another file?
Any help would be greatly appretiated,
illu45 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Bacchus
![](http://img104.exs.cx/img104/9206/ravenmoon12ns.jpg)
|
Posted: Sat Mar 05, 2005 10:52 pm Post subject: (No subject) |
|
|
include "" prettu sure theres a tutorial on it too |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sun Mar 06, 2005 8:17 am Post subject: (No subject) |
|
|
Bacchus: Include is not what he's looking for. He's looking for a way to make one class inherit all the procedures and functions of a previously built class. If you try to include the other file, it's the same as copying and pasting all the code inside the Basic.t file inside the main class. So it would look like this:
code: |
class main
export stuff
class basic
export ...
end class
end class
|
That won't work, as you'll get the "Classes may only be declared at the program, monitor, or module level."
illu45: I could be wrong, but I think this will help you:
Turing Reference wrote:
An inheritItem is one of:
(a) id
(b) id in fileName
The second form is used when the inherit clause is for a separate unit and the imported item is in a file whose name is different from the item's name, for example:
inherit ledger in "newledg.t"
The fileName must be an explicit character string, e.g., "newledg.t". Parentheses are allowed around the item in an inherit clause, as in:
inherit ( ledger in "newledg.t" )
So, make Basic.t into a unit it and save it as Basic.tu. Then use inherit in fileName.
Hope that helps,
-Cervantes |
|
|
|
|
![](images/spacer.gif) |
Bacchus
![](http://img104.exs.cx/img104/9206/ravenmoon12ns.jpg)
|
Posted: Sun Mar 06, 2005 8:48 am Post subject: (No subject) |
|
|
ok then, wasnt sur4e wat they meant guess i was wrong lol |
|
|
|
|
![](images/spacer.gif) |
illu45
![](http://img9.exs.cx/img9/1348/roadavvy2ht.png)
|
Posted: Sun Mar 06, 2005 9:58 am Post subject: (No subject) |
|
|
I tried renaming the basic.t into basic.tu (adding unit to it), and theninheriting it into main.t, however, I get 'basic has not been declared'. If I try to import "basic.tu" then I get Cannot inherit symbol 'basic' unless it is in the same scope... |
|
|
|
|
![](images/spacer.gif) |
|
|