请看看我的才c++程序那里错了?

来源:百度知道 编辑:UC知道 时间:2024/06/30 05:01:16
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
class quoter{
public:
quoter();
int lastquote()const;
const char*quote();
private:
int lastquote;
};
quoter::quoter(){
lastquote=-1;
srand(time(0));
}
int quoter::lastquote()const{
return lastquote;
}
const char*quoter::quote(){
static const char* quotes[]={
" Are we having char* quotes",
"doctors always know best",
"is it ... atomic?",
"fear is obscene",
"there is no scienific ebidence",
"to support the idea ",
"that life is serious",
"things that make us happy ,make us wise",
};
const int qsize=sizeof quotes/sizeof*quotes;
int qnum=rand()%qsize;
while(lastquote >= 0 && qnum==lastquote)
qnum=rand()%qsize;
ret

你的成员同函数名相同了!
这是我改的:

#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;

class quoter
{
public:
quoter();
int lastquote()const;
const char*quote();
private:
int m_lastquote;
};
quoter::quoter(){
m_lastquote=-1;
srand(time(0));
}
int quoter::lastquote()const{
return m_lastquote;
}

const char* quoter::quote()
{
static const char* quotes[]={
" Are we having char* quotes",
"doctors always know best",
"is it ... atomic?",
"fear is obscene",
"there is no scienific ebidence",
"to support the idea ",
"that life is serious",
"things that make us happy ,make us wise",
};
const int qsize=sizeof quotes/sizeof*quotes;
int qnu