I get the following error in XCode whenever I try to access the member I created 'randomGen' in a separate class in a different header file.
I have made sure to include the header file and have tried to access it through an object.
This is the code I enter when trying to access the method from randomiser.h in main.cpp. It is also an overloaded function with doubles and integers:
1 2
|
RandomG randomiser;
randomiser.randomGen(); // 'Call to member function 'randomGen' is ambiguous'
|
This is the code inside randomiser.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include <string>
#include <iostream>
using std::string;
using std::cout;
using std::endl;
class RandomG
{
private:
// This is private
public:
// Public
RandomG();
~RandomG();
// Methods
int randomGen(int generatedNumber = NULL, int range = 2);
int randomGen(double generatedNumber = NULL, int range = 1);
};
class passwordManagement
{
public:
// Public
passwordManagement();
~passwordManagement();
// Methods
int passReset();
private:
// Private
};
passwordManagement::passwordManagement()
{
std::cout << "Constructing password management class" << std::endl;
}
passwordManagement::~passwordManagement()
{
std::cout << "Destructing password management class" << std::endl;
}
RandomG::RandomG()
{
std::cout << "Constructing random class" << std::endl;
srand((unsigned int)time(NULL));
}
RandomG::~RandomG()
{
std::cout << "Destructing random class" << std::endl;
}
int RandomG::randomGen(int generatedNumber, int range)
{
// Generates a random number from range and returns it
generatedNumber = 1+(rand()%range);
return generatedNumber;
};
int RandomG::randomGen(double generatedNumber, int range)
{
// Generates a random decimal number from range and returns it
generatedNumber = 1+(rand()%range);
return generatedNumber;
};
int passwordManagement::passReset()
{
return 0;
};
|
This is the error inside xcode:
http://puu.sh/77i1f.png
I have tried seperating the code for the functions in another class (main.cpp) and then running and it seems to works, so I'm not sure why I can't put everything in the .h file and then access it?
I would like it in a seperate file so it doesn't clutter my main. I am writing a game with SDL so that might be confusing and I would like the window to have a random title and other random properties, so it would be easier to use a function.
Its also practice with using them, because I am new to C++. Please make your answer as noob friendly as possible, so I can understand.
Thanks in advance, and sorry if my post needs amending in some way. If so I will.
- exitcode
(I didn't shorten the code inside the header file as I think it is all relavent).