Thread: constructor?

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    1
    Rep Power
    0

    constructor?


    i get this error msg:
    error C2512: 'RndNum' : no appropriate default constructor available

    when im using this code:
    // Implementing the reel.h file into reel.cpp //

    #include "Reel.h"
    #include "RndNum.h"

    // Construction/Destruction //

    int REEL::spin()
    {
    RndNum ran;
    currentSymbol = ran.generateNumber();
    return currentSymbol;
    }

    int REEL::getCurrentSymbol()
    {
    return spin();
    }

    im tryin to use my rndnum class to generate a randomnumber each time a reel is spun, have i gone the wrong way about this or is their a simple answer to my problem?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    138
    Rep Power
    11
    It would help if u give the class definitions
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    Most likely, you defined a constructor something like this:

    RndNum(int a, double b)
    {
    //code here
    }

    Well, that means you have a constructor that takes two parameters. When you declare your RndNum variable here:

    RndNum ran;

    you will notice you did not provide the two parameters your constructor requires, e.g.:

    RndNum ran(6, 5.25);

    So, the compiler looked for a constructor you defined with no parameters, and it couldn't find one.

    The rule is: if you don't define a constructor, the compiler will provide a default constructor, i.e. one with no parmaters, but if you define any constructor for your class, the compiler won't supply a default constructor for you.
    Last edited by 7stud; August 4th, 2003 at 07:40 PM.

IMN logo majestic logo threadwatch logo seochat tools logo