ToString / toString
Posted: Fri Feb 08, 2008 5:04 am
This is what I get when I try to override the method toString:
hello.cobra(47): error: Cannot return String because "toString" is declared to return a void.
What's wrong? Isn't it supposed to return a string?
this is my class:
class Dude
shared
var _l = List<of Dude>()
var _name = ''
var _last = ''
var _age as int
def init(name as String, last as String, age as int)
_name = name.toUpper
_last = last.toUpper
_age = age
_l.add(this)
pro name from var
pro last from var
pro age from var
pro l from var
def toString is override
return '[_name] [_last]'
hello.cobra(47): error: Cannot return String because "toString" is declared to return a void.
What's wrong? Isn't it supposed to return a string?
this is my class:
class Dude
shared
var _l = List<of Dude>()
var _name = ''
var _last = ''
var _age as int
def init(name as String, last as String, age as int)
_name = name.toUpper
_last = last.toUpper
_age = age
_l.add(this)
pro name from var
pro last from var
pro age from var
pro l from var
def toString is override
return '[_name] [_last]'