エラー:
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;
}