0

I'm trying to create a classes in separate files using codeblocks. I get the error in function '_start' undefined reference to 'main'. I'm sure its a linkage problem but can't see where. In my program I’m trying to get a die, let the user decide how many sides the dice has, then roll the die a user specified amount of times.

die.h  file///////////////////////////////////

#include <iostream>
#include <string>
#ifndef DIE_H
#define DIE_H

using namespace std;

class die{

public:

    die();//function prototype

    int numsides;//member
    void setNumsides(int numsides_);//setter 
    int getNumsides();// getter for size of dice

    int value;
    void setValue(int value_, int numsides_);
    int getValue();

    int roll;
    void setroll(int roll_);
    int getroll();

};
#endif// DIE_H


die.cpp//////////////////////////////////////////

#include "die.h"
#include <iostream>
#include <string>
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */



using namespace std;


die::die()
{
    //ctor
}
void die::setroll(int roll_)
    {
        roll=roll_;
    }

int die::getroll()//amount o rolls
    {
        cout << "enter the ammont of rolls you would like" << endl;
        cin >> roll;//amount of rolls you want
        return roll;

    }

void die::setValue(int value_, int numsides_)
    {
        value=value_;
        numsides=numsides_;
    }

int die::getValue()//get value function
    {
        //int roll;
        value = (rand() % numsides) + 1;//sets roll value
        return value;
    }

void die::setNumsides(int numsides_)
    {
        numsides=numsides_;
    }

int die::getNumsides()//get num of sides
    {
        cout << "how big of a dice would you like to roll " << endl;
        cin >> numsides;//use this to determine dice

        if(numsides < 4){//if dice is less than 4
            cout << "Error has to be bigger than " << numsides << endl;
            numsides = 6;//change to six sided dice
        }
        return numsides;
    }


exercise1.cpp my main class/////////////////////////////////////


#include <iostream>
#include <stdlib.h>     /* srand, rand */
#include <time.h>
#include "die.h"

using namespace std;

int main()
{
    die mydice;//create an object dice

    mydice.getNumsides();//gets sides of dice

    mydice.getValue();//gets amount of rolls

    mydice.getroll();//rolls the dice value times


return 0;
}
bri
  • 17
  • 5

0 Answers0