Error about no such function "new()"

12 views
Skip to first unread message

Ryan Gonzalez

unread,
Jul 9, 2015, 1:59:45 PM7/9/15
to ooc-...@googlegroups.com
I have this code:

import math/Random

Animal: abstract class {
    makeNoise: abstract func
}

Sheep: class extends Animal {
    makeNoise: func {
        "Baaaaaaa!" println()
    }
}

Wolf: class extends Animal {
    makeNoise: func {
        "Hooooowl!" println()
    }
}

"Enter a number between 0 (inclusive) and 3 (exclusive)" println()
badNumber := Random randRange(0, 3)
inputNumber := stdin readLine() toInt()
animals := [Sheep new(), Sheep new(), Sheep new()]
animals[badNumber] = Wolf new()
"Animal noise:" println()
animals[inputNumber] makeNoise()
match (animals[inputNumber]) {
    case sheep: Sheep => { "It's a stupid, annoying sheep!" println() }
    case wolf: Wolf => { "AHH! A WOLF! You got eaten. :/ R.I.P." println() }
}

When I try to compile it, I get this:

ryan@DevPC-LX:~/golf/obs$ rock -v spec.ooc
Parsing...
Resolving...

obs/spec.ooc:22:13 error No such function new() for `SheepClass`
animals := [Sheep new(), Sheep new(), Sheep new()]
            ~~~~~~~~~                             

[FAIL]
ryan@DevPC-LX:~/golf/obs$ 

What am I doing wrong???

--
Ryan
[ERROR]: Your autotools build scripts are 200 lines longer than your program. Something’s wrong.

Amos Wenger

unread,
Jul 9, 2015, 3:51:39 PM7/9/15
to Ryan Gonzalez, ooc-...@googlegroups.com
As of some versions ago, rock doesn't add default constructors anymore.

Just add `init: func` to your non-abstract classes and everything should start working!

Cheers,
- Amos

--
You received this message because you are subscribed to the Google Groups "ooc-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ooc-lang+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ryan Gonzalez

unread,
Jul 9, 2015, 5:10:02 PM7/9/15
to amosw...@gmail.com, ooc-...@googlegroups.com
Ah! Thank you!
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Reply all
Reply to author
Forward
0 new messages