错误:
expected ‘,’ or ‘...’ before ‘&’ token
randomNumberMagnifier.h:32: error: ISO C++ forbids declaration of ‘randomNumberMagnfier’ with no type
randomNumberMagnifier.h:32: error: ‘std::ostream& randomNumberMagnifier::operator<<(std::ostream&, int)’ must take exactly one argument
[singha1@cs1 p4]$
这是不断出现的错误。我几乎已经复制了重载的代码operator<<
来打印用户这些运算符的值。
。H:
#ifndef RANDOMNUMBERMAGNIFIER_H
#define RANDOMNUMBERMAGNIFIER_H
#include <iostream>
#include <fstream>
using namespace std;
class randomNumberMagnifier
{
int addFactor;
int multFactor;
bool addOn;
bool multOn;
int randomNumber;
static const int MAX_ADD_FACTOR = 100;
static const int MAX_MULT_FACTOR = 20;
static const int MAX_RANDOM = 200;
public:
randomNumberMagnifier();
randomNumberMagnifier(const randomNumberMagnifier& arandom);
//~randomNumberMagnifer();
randomNumberMagnifier& operator=(const randomNumberMagnifier& rhs );
// randomNumberMagnifier& operator==(const randomNumberMagnfier& rhs );
ostream& operator<<(ostream& o, const randomNumberMagnfier& rhs );
randomNumberMagnifier(bool aState, bool mState);
int randomMagnifier();
int getAdd();
int getMult();
bool getAddState();
bool getMultState();
int getRandomNumber();
void display(ostream& out) const;
};
#endif
.cpp:
ostream& operator<<(operator& out, const randomNumberMagnifier& rhs)
{
rhs.display(out);
return out;
//cout << this->getAdd()=rhs.getAdd();
/*
cout << this->multFactor;
cout << this->addOn;
cout << this->multOn;
cout << this->randomNumber;
*/
}
void randomNumberMagnifier :: display(ostream& out)const
{
out << addFactor << multFactor << randomNumber;
}