"Error: function expected before (), not module *module* of type void
Dustin Mays
dustin.biggins.mays at gmail.com
Mon Mar 24 01:28:12 PDT 2008
I'm getting the following error message when trying to compile a test-app I wrote:
diceroller.d(9): Error: function expected before (), not module rollDice of type void
Here is my code:
diceroller.d:
module diceroller;
import tango.io.Stdout;
import rollDice;
void main()
{
Stdout (rollDice(6)).newline;
}
rollDice.d:
module rollDice;
import tango.math.Random;
uint rollDice(uint sides)
{
uint result = 0;
Random dice_Roller;
dice_Roller = new Random();
result = dice_Roller.next(1, (sides + 1));
return result;
}
When I put the rollDice function in diceroller.d, all is well, compiles fine, and works as expected. But when I try to put it in a seperate module, rollDice.d, it doesn't work anymore. Note: I'm a newbie just learning D, and I'm pretty new with programming in general, so I don't quite know what's going on. :p
Note: I think I should explain the following bit of code real quick: result = dice_Roller.next(1, (sides + 1));. As I understand it, Random.next(uint min, uint max) returns a value x where min <= x < max. So when Random.next(1,6) is called, you'll only get values between 1-5, since x can't equal the max value. I used "result = dice_Roller.next(1, (sides + 1))" so that I could write a more natural interface, as calling rollDice(7) to simulate a six-sided die would seem awkward.
Thanks in advance for any advice. :)
Dustin Mays
More information about the Digitalmars-d-learn
mailing list