I've just started looking at C++ and I am having some problems I can't wrap my head around.
I am trying to do something as simple as creating a class with a function, call that function and read the returned value.
However I am stuck at what I guess is a minor issue.
I know that it is the call from main to Die -> randomNumber that causes this error but I dont know why. I even tried to return the number 12 from the function without any luck.
I have 3 files (main.cpp, Die.h and Die.cpp)
main.cpp
#include <string>
#include "Die.h"
using namespace std;
int main() {
Die * test = new Die();
cout << std::to_string(test->randomNumber(4)) << endl;
return 0;
}
Die.h
#pragma once
#include <iostream>
#include <ctime>
#include <cstdlib>
class Die
{
public:
Die();
~Die();
void init();
void rollDie(int&, int&);
void rollDie(int*, int*);
int randomNumber(int);
};
Die.cpp
#include "Die.h"
Die::Die()
{
}
Die::~Die()
{
}
void Die::init() {
}
int randomNumber(int max) {
srand(static_cast<unsigned int>(time(0)));
return (rand() % max + 1);
}
void rollDie(int& die1, int& die2) {
}
void rollDie(int* die1, int* die2) {
}