J
Jag
When I compile the program below I get this error. I don't understand
what is happening.
Please help. It works in VC++
---------------------------------------------------------------------
gcc version 3.4.6 20060404 (Red Hat 3.4.6-8)
test.cpp: In function `int main()':
test.cpp:28: error: expected `;' before "r"
test.cpp:28: warning: statement is a reference, not call, to function
`srandom'
test.cpp:29: error: `r' was not declared in this scope
--------------------------------------------------
#include <iostream>
#include <fstream>
#include <assert.h>
#include <time.h>
#include <iomanip>
class srandom {
public:
srandom() {srand((unsigned)time(0)); }
int get_random_number(int a = 0, int b = 10000) const {
int upper_bound, lower_bound;
if(a < b) {upper_bound = b - a; lower_bound = a;}
else if(a >= b) {upper_bound = a - b; lower_bound = b;}
return(lower_bound + rand() % upper_bound);
}
private:
/* no body can copy srandom or equal srandom */
srandom(const srandom& x);
srandom& operator=(const srandom& x);
};
main() {
srandom r;
int real = r.get_random_number() ;
}
what is happening.
Please help. It works in VC++
---------------------------------------------------------------------
gcc version 3.4.6 20060404 (Red Hat 3.4.6-8)
test.cpp: In function `int main()':
test.cpp:28: error: expected `;' before "r"
test.cpp:28: warning: statement is a reference, not call, to function
`srandom'
test.cpp:29: error: `r' was not declared in this scope
--------------------------------------------------
#include <iostream>
#include <fstream>
#include <assert.h>
#include <time.h>
#include <iomanip>
class srandom {
public:
srandom() {srand((unsigned)time(0)); }
int get_random_number(int a = 0, int b = 10000) const {
int upper_bound, lower_bound;
if(a < b) {upper_bound = b - a; lower_bound = a;}
else if(a >= b) {upper_bound = a - b; lower_bound = b;}
return(lower_bound + rand() % upper_bound);
}
private:
/* no body can copy srandom or equal srandom */
srandom(const srandom& x);
srandom& operator=(const srandom& x);
};
main() {
srandom r;
int real = r.get_random_number() ;
}