Help me please

This is a discussion on Help me please within the C++ Programming forums, part of the General Programming Boards category; what do this error mean? Code: error C2084: function 'int __thiscall dice::numSides(void)' already has a body...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    35

    Help me please

    what do this error mean?

    Code:
    error C2084: function 'int __thiscall dice::numSides(void)' already has a body

  2. #2
    Unregistered
    Guest
    You probably have two functin declarations or definitions of the numsides() in your dice class

  3. #3
    Still A Registered User DISGUISED's Avatar
    Join Date
    Aug 2001
    Posts
    499
    You probably declare the same function in two different places. Post your code.

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    35
    ok, my teacher had us split the dice.h into dice.h and dice.cpp, and include the dice.cpp in with the dice.h, I think that might be my problem, is there a way make this work without merging them back together

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    591
    Your function schould be declared in dice.h like this

    void DoSomething();

    and defined in your dice.cpp

    void DoSomething()
    {
    bla bla;
    }

    include your dice.h in the top of your dice.cpp like this

    #include "dice.h"

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    35
    yeah, I did that

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    591
    How about if you help us to help you and post some code

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    35
    dice.h
    Code:
    #ifndef _DICE_H
    #define _DICE_H
    
    
    class dice{
    	public:
    		dice(int sides);
    		int roll();
    		int numSides();
    		int numRolls();
    	private:
    		int mySides;
    		int myRollCount;
    };
    
    
    
    #endif
    dice.cpp
    Code:
    //dice.cpp
    
    #include <stdlib.h>
    #include <time.h>
    #include <limits.h>
    #include "dice.h"
    
    dice::dice (int sides)
    {
    	long time = clock();
    
    	srand(time % INT_MAX);
    	mySides = sides;
    }
    
    int dice::roll()
    {
    	return (rand() % mySides) + 1;
    }
    
    int dice::numSides()
    {
    	return mySides;
    }
    
    int dice::numRolls()
    {
    	return myRollCount;
    }

  9. #9
    Registered User
    Join Date
    Mar 2002
    Posts
    35
    I got it going, thanks for the help

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21