Good morning everyone.
Have a question about calling one of my dice roll functions from inside a class i have made.
Is this possible to do with C++?
I'm getting identifier not found errors. for d10Roll()
Is there a different way i need to go about this?
1 2 3 4 5 6 7 8 9 10
void TheDarklake::getCollision() {
int d10a = d10Roll();
int d10b = d10Roll();
int d10c = d10Roll();
std::cout << "------------------------------ Collision -----------------------------" << std::endl;
std::cout << "This terrain encounter occurs only if one or more party members are " << std::endl;
std::cout << "traveling by raft or boat, and there's a strong current. Have everyone" << std::endl;
}
Ok i understand now.
So, I'd have to create a d10Roll(); function in every class I create that uses a dice roll?
I can't use the random dice functions I already have in my main source.cpp file?
You can write the implementation of d10Roll in TheDarkLake or whichever class you prefer and then include the header of that class into another class
so if you have source.cpp
1 2 3 4 5 6 7 8 9 10 11 12
#include "TheDarklake.h"
int main()
{
TheDarklake darklake;
darklake.d10Roll();
}
if you dont like that approach you can do something called forward declaration.
Given that the class which called TheDarklake class will have the d10Roll() implementation you can do something like this
#include "TheDarkLake.h"
void d10Roll(); // forward declaration here promising the compiler that this function indeed exists later in the code.
TheDarkLake::TheDarkLake()
{
d10Roll();
}
TheDarkLake::~TheDarkLake()
{
}