我正在尝试重载<<运算符,但我得到一个错误,低于.
rollingDice.h|14|error: ‘std::ostream& rollingDice::operator<<(std::ostream&, const rollingDice&)’ must take exactly one argument|
Run Code Online (Sandbox Code Playgroud)
这是我的代码.我将执行和删除分开了.我认为问题的出现是因为我的编码和很多网页和Deitel&Deitel一样.
rollingDice.cpp
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <stdlib.h>
#include "rollingDice.h"
using namespace std;
rollingDice::rollingDice(unsigned int valN)
{
n=valN;
r=new int [n];
}
int rollingDice::length()
{
return n;
}
void rollingDice::generate()
{
srand48(time(NULL));
int i=0;
for (i=0; i<n; ++i)
{
r[i]=1+(lrand48()%6);
}
}
rollingDice& rollingDice::init(unsigned int valN)
{
n=valN;
r=new int [n];
return *this;
}
ostream& operator << (ostream& output, rollingDice& rd)
{
int temp=n;
if (temp>12)
temp=12; …Run Code Online (Sandbox Code Playgroud)