
-----------------------------------
Clayton
Tue May 30, 2006 9:09 am

calling classes
-----------------------------------
is it possible to call a class from within a class? for example, i have a game where weapons have stats, but these stats are needed for another class for a character that the user uses, so im just wondering if i can call that class from within my Character class or if i have to do it outside the class (obviously inside would be easier as it would allow me to have many instances of the class)

-----------------------------------
Delos
Tue May 30, 2006 10:37 am


-----------------------------------
Do you mean calling a method of a class?  Something like:


class Class1
  export main
  proc main
    put "Class1 main"
  end main
end Class1

class Class2
  export main
  proc main
    var temp : ^Class1
    new Class1, temp
    temp -> main
    put "in Class2 main"
  end main
end Class2

var foo : ^Class2
new Class2, foo

foo -> main


That code is untest!  I don't have access to Turing right now, so it's likely buggy here and there...but yes, it is possible to insantiate an object of a Class within another class.  I wouldn't be surprised if you could instantiate an object of that same class within a class...though for what reasons, I'm not too sure...

-----------------------------------
Clayton
Tue May 30, 2006 10:45 am


-----------------------------------
ok thanks thats pretty much exactly what i wanted to know :D

-----------------------------------
Cervantes
Tue May 30, 2006 3:16 pm


-----------------------------------
I wouldn't be surprised if you could instantiate an object of that same class within a class...though for what reasons, I'm not too sure...

Any sort of structure that links to others like it. A node is the classic example, for the use of creating a really need to work on your terminology. If not for Delos' post, I would have no clue what you're asking. You don't "call a class". Heck, you don't even call a method of that class. You call a method of an instance of that class.
