我想调用'int Random :: random(int lower,int upper)函数,但是我得到一个问题,说'成员函数不能在类之外重新声明'我也尝试提供以下形式的解决方案:调用成员函数,在类之外声明
'Random m; m.Random()”
这下面要说的问题 '在函数调用太少参数'
下面是main.cpp的文件
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
#include "Circle.h"
#include "Random.h"
int main()
{
Random m;
m.random();
// Array 1, below section is to populate the array with random
// radius number within lower and upper range
int CircleArrayOne [5];
const int NUM = 5;
srand(time(NULL));
for(int x = 0; x < NUM; ++x)
{
int Random::random(int lower, int upper);
}
// output the radius of each circle
cout << "Below is the radius each of the five circles in the second array. " << endl;
// below is to output the radius in the array
for(int i = 0; i < NUM; ++i)
{
cout << CircleArrayOne[i] << endl;
}
system("PAUSE");
return 0;
}
int Random::random(int lower, int upper)
{
cout << "Enter lower number: " << lower << endl;
cout << "Enter upper number: " << upper << endl;
int range = upper - lower + 1;
return (rand() % range + lower);
}
下面是Random.h文件
#pragma once
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
class Random
{
public:
static void initialiseSeed();
// random number initialised
// random number has been initialised to the current time.
static int random(int lower, int upper);
// this function will return a positive random number within a specific lower and
// upper boundary.
};
请问您能帮我解决问题吗? 所有帮助是非常赞赏