Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Figuring out what class a variable is
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
smool




PostPosted: Sat Dec 10, 2011 1:48 am   Post subject: Figuring out what class a variable is

What is it you are trying to achieve?
Say I have a Weapon parent class, and then a Ranged child class and a Melee child class, is there a way to check to see if my pointer is pointing to a Ranged class or Weapon class?

maybe something like:

Turing:

import Weapon, Ranged, Melee

var w : ^Weapon

if w Is Ranged then
    put "You are carrying a ranged weapon"
elsif w Is Melee then
    put "You are carrying a melee weapon"
end if


is there any way to do that aside from making boolean variables in the parent class and calling those?
Sponsor
Sponsor
Sponsor
sponsor
Nick




PostPosted: Sat Dec 10, 2011 6:27 am   Post subject: RE:Figuring out what class a variable is

I think you're looking for objectclass. Take a look at the following

Turing:

class Foo
end Foo

class Bar
    inherit Foo
end Bar

class Baz
    inherit Foo
end Baz


var foo : ^Foo
new Foo, foo
var bar : ^Bar
new Bar, bar
var baz : ^Baz
new Baz, baz

if objectclass (foo) = Foo then
    put "foo is Foo"
end if

if objectclass (bar) >= Foo then
    put "bar is at least Foo"
end if

if objectclass (foo) < Baz then
    put "foo is a parent of Baz"
end if
smool




PostPosted: Thu Dec 15, 2011 4:59 pm   Post subject: RE:Figuring out what class a variable is

thx Very Happy
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: