我想编一个图书管理系统:
我设计里一个基类:object
book类:public object
可是编译为马说从定义类:object??
程序如下:
//object.h
//////////////////////////////////////////////////////////////////////////////////////////////////
/////// this is base class ! book class,reader class and librarian class from lllllobject!!
///////Attribute: index,name!
///////operator: Getname,Setname!
///////
///////2004.5.7 zk
///////
//////////////////////////////////////////////////////////////////////////////////////////////////
#include<iostream>
#include<string>
using namespace std;class object
{
private:
int index;
string name;
public:
object();
object(int,string);
// ~object();i can not write code !!so bad!!dont forget it!!
virtual string Getname();
virtual int Getindex();
virtual const object& Getobject();
virtual void Setname(string);
virtual void Setindex(int);
void Setobject(const object);
const object& operator=(const object& );
};
//object.cpp
#include<iostream>
#include<string>
#include"object.h"
using namespace std;object::object()
{
index=-1;
name ="无";
}
object::object(int i,string n):index(i),name(n)
{}
int object::Getindex()
{return index;}
string object::Getname()
{return name;}
const object& object::Getobject()
{return *this;}
void object::Setindex(int i)
{index=i;}
void object::Setname(string n)
{name=n;}
void object::Setobject(const object o)
{*this=o;}
const object& object::operator=(const object& o)
{
index=o.index;
name=o.name;
return *this;
}
//book.h
/////////////////////////////////////////////////////////////////////////////////////////////////
//////this is book class! public:object!
//////Attribute:index,bookname,writername,publishing company ,state(borrow),re,CDROM,Filename
//////operator:Checkout,ShowData,Setbookname,Setindex,Set..
//////Getbookename.........Get..
//////2004.5.7 zk
/////////////////////////////////////////////////////////////////////////////////////////////////
#include<iostream>
#include<string>
#include"object.h"
using namespace std;
class book :public object
{
private:
// int index;
// string bname;
string wname;
string pubcomname;
bool state;
string re;
bool CDROM;
//static const char FileName[15];
public:
book();
book(int i,string bookname,string writername,string publishcompany,bool s,bool CDROM,string r);
book(int i,string bookname,string writername,string publishcompany,bool s,bool CDROM);
//~book();
void Setindex(int);
void Setbookname(string);
void Setwritername(string);
void Setpublishcompany(string);
void Setstate(bool);
void SetCDROM(bool);
void Setre(string); int Getindex(void);
string Getbookname(void);
string Getwritername(void);
string Getpublishcompany(void);
bool Getstate(void);
bool GetCDROM(void);
string Getre(void); void CheckOut();
};
//const char book::FileName[15]="Book.txt";
//const char *book::GetFileName();
//book.cpp
#include<iostream>
#include<string>
#include"object.h"
#include"book.h"
using namespace std;
book::book()
{
object() ;
// index=-1;
// bname="无";
wname="无";
pubcomname="无";
state=0;
re="三无";
CDROM=0;
}
book::book(int i,string bookname,
string writername,string publishcompany,
bool s,bool c,string r)
{
object(i,bookname) ;
//index=i;
// bname=bookname;
wname=writername;
pubcomname=publishcompany;
state=s;
re=r;
CDROM=c;
}
book::book(int i,string bookname,string writername,string publishcompany,bool s,bool c)
{
object(i,bookname) ;
// index=i;
// bname=bookname;
wname=writername;
pubcomname=publishcompany;
state=s;
re="";
CDROM=c;
}
void book::Setindex(int i)
{object::Setindex(i);}
void book::Setbookname(string n)
{object::Setname(n);}
void book::Setwritername(string w)
{wname=w;}
void book::Setpublishcompany(string pc)
{pubcomname=pc;}
void book::Setstate(bool s)
{state=s;}
void book::SetCDROM(bool CD)
{CDROM=CD;}
void book::Setre(string r)
{re=r;}
int book::Getindex(void)
{return object::Getindex();}
string book::Getbookname(void)
{
//return bname;
return object::Getname();
}
string book::Getwritername(void)
{return wname;}
string book::Getpublishcompany(void)
{return pubcomname;}
bool book::Getstate(void)
{return state;}
bool book::GetCDROM(void)
{return CDROM;}
string book::Getre(void)
{return re;}
void book::CheckOut()
{
if (state==0)
throw("Book is not in library!");
state=0;
}
我设计里一个基类:object
book类:public object
可是编译为马说从定义类:object??
程序如下:
//object.h
//////////////////////////////////////////////////////////////////////////////////////////////////
/////// this is base class ! book class,reader class and librarian class from lllllobject!!
///////Attribute: index,name!
///////operator: Getname,Setname!
///////
///////2004.5.7 zk
///////
//////////////////////////////////////////////////////////////////////////////////////////////////
#include<iostream>
#include<string>
using namespace std;class object
{
private:
int index;
string name;
public:
object();
object(int,string);
// ~object();i can not write code !!so bad!!dont forget it!!
virtual string Getname();
virtual int Getindex();
virtual const object& Getobject();
virtual void Setname(string);
virtual void Setindex(int);
void Setobject(const object);
const object& operator=(const object& );
};
//object.cpp
#include<iostream>
#include<string>
#include"object.h"
using namespace std;object::object()
{
index=-1;
name ="无";
}
object::object(int i,string n):index(i),name(n)
{}
int object::Getindex()
{return index;}
string object::Getname()
{return name;}
const object& object::Getobject()
{return *this;}
void object::Setindex(int i)
{index=i;}
void object::Setname(string n)
{name=n;}
void object::Setobject(const object o)
{*this=o;}
const object& object::operator=(const object& o)
{
index=o.index;
name=o.name;
return *this;
}
//book.h
/////////////////////////////////////////////////////////////////////////////////////////////////
//////this is book class! public:object!
//////Attribute:index,bookname,writername,publishing company ,state(borrow),re,CDROM,Filename
//////operator:Checkout,ShowData,Setbookname,Setindex,Set..
//////Getbookename.........Get..
//////2004.5.7 zk
/////////////////////////////////////////////////////////////////////////////////////////////////
#include<iostream>
#include<string>
#include"object.h"
using namespace std;
class book :public object
{
private:
// int index;
// string bname;
string wname;
string pubcomname;
bool state;
string re;
bool CDROM;
//static const char FileName[15];
public:
book();
book(int i,string bookname,string writername,string publishcompany,bool s,bool CDROM,string r);
book(int i,string bookname,string writername,string publishcompany,bool s,bool CDROM);
//~book();
void Setindex(int);
void Setbookname(string);
void Setwritername(string);
void Setpublishcompany(string);
void Setstate(bool);
void SetCDROM(bool);
void Setre(string); int Getindex(void);
string Getbookname(void);
string Getwritername(void);
string Getpublishcompany(void);
bool Getstate(void);
bool GetCDROM(void);
string Getre(void); void CheckOut();
};
//const char book::FileName[15]="Book.txt";
//const char *book::GetFileName();
//book.cpp
#include<iostream>
#include<string>
#include"object.h"
#include"book.h"
using namespace std;
book::book()
{
object() ;
// index=-1;
// bname="无";
wname="无";
pubcomname="无";
state=0;
re="三无";
CDROM=0;
}
book::book(int i,string bookname,
string writername,string publishcompany,
bool s,bool c,string r)
{
object(i,bookname) ;
//index=i;
// bname=bookname;
wname=writername;
pubcomname=publishcompany;
state=s;
re=r;
CDROM=c;
}
book::book(int i,string bookname,string writername,string publishcompany,bool s,bool c)
{
object(i,bookname) ;
// index=i;
// bname=bookname;
wname=writername;
pubcomname=publishcompany;
state=s;
re="";
CDROM=c;
}
void book::Setindex(int i)
{object::Setindex(i);}
void book::Setbookname(string n)
{object::Setname(n);}
void book::Setwritername(string w)
{wname=w;}
void book::Setpublishcompany(string pc)
{pubcomname=pc;}
void book::Setstate(bool s)
{state=s;}
void book::SetCDROM(bool CD)
{CDROM=CD;}
void book::Setre(string r)
{re=r;}
int book::Getindex(void)
{return object::Getindex();}
string book::Getbookname(void)
{
//return bname;
return object::Getname();
}
string book::Getwritername(void)
{return wname;}
string book::Getpublishcompany(void)
{return pubcomname;}
bool book::Getstate(void)
{return state;}
bool book::GetCDROM(void)
{return CDROM;}
string book::Getre(void)
{return re;}
void book::CheckOut()
{
if (state==0)
throw("Book is not in library!");
state=0;
}
看看具体的提示啊
--------------------Configuration: library - Win32 Debug--------------------
Compiling...
book.cpp
g:\program files\microsoft visual studio\myprojects\library\object.h(13) : error C2011: 'object' : 'class' type redefinition
Error executing cl.exe.book.obj - 1 error(s), 0 warning(s)
object类是你自己写的?????
C++本来自己就有一个object类,如果object类是你自己写的话,那把object的名字改一下吧~~!!
/////// this is base class ! book class,reader class and librarian class from lllllobject!!
///////Attribute: index,name!
///////operator: Getname,Setname!
///////
///////2004.5.7 zk
///////
//////////////////////////////////////////////////////////////////////////////////////////////////
#include<iostream>
#include<string>
using namespace std;
class libraryobject
{
private:
int index;
string name;
public:
libraryobject();
libraryobject(int,string);
// ~libraryobject();i can not write code !!so bad!!dont forget it!!
string Getname();
int Getindex();
const libraryobject& Getobject();
void Setname(string);
void Setindex(int);
void Setobject(const libraryobject);
const libraryobject& operator=(const libraryobject& );
};
#include<iostream>
#include<string>
#include"libraryobject.h"
using namespace std;libraryobject::libraryobject()
{
index=-1;
name ="无";
}
libraryobject::libraryobject(int i,string n):index(i),name(n)
{}
int libraryobject::Getindex()
{return index;}
string libraryobject::Getname()
{return name;}
const libraryobject& libraryobject::Getobject()
{return *this;}
void libraryobject::Setindex(int i)
{index=i;}
void libraryobject::Setname(string n)
{name=n;}
void libraryobject::Setobject(const libraryobject o)
{*this=o;}
const libraryobject& libraryobject::operator=(const libraryobject& o)
{
index=o.index;
name=o.name;
return *this;
}
SetName(string)??
--------------------Configuration: library - Win32 Debug--------------------
Compiling...
reader.cpp
D:\MyProjects\library\reader.cpp(33) : error C2352: 'object::SetName' : illegal call of non-static member function
d:\myprojects\library\object.h(51) : see declaration of 'SetName'
Error executing cl.exe.reader.obj - 1 error(s), 0 warning(s)
/////this is a reader class! public:object
/////attribute:index,name,sex,age,phone,re,address,..
/////options:borrowbook,give back book,show data,and set........Get..........
/////
/////2004.5.7 zk
//////////////////////////////////////////////////////////////////////////////////////////////////
#include<iostream>
#include<string>
#include "object.h"
using namespace std;
class reader:public object
{
private:
string sex;
int age;
string adpartment;
string phone;
string profession;
string address;
string re;
static const char FileName[15];
public:
reader();
reader(int i,string name,string s,int ag,string a,string ph,string pr,string ad="",string re="");
void SetIndex(int i);
void SetName(string n);
void Setsex(string s);
void Setage(int a);
void Setadpartment(string a);
void Setphone(string p);
void Setprofession(string p);
void Setaddress(string a);
void Setre(string r); int GetIndex();
string GetName();
string Getsex();
int Getage();
string Getadapartment();
string Getphone();
string Getprofession();
string Getaddress();
string Getre();
// void showdata();
void Borrowbook(int i);
void giveback(int i);
////
static const char *GetFileName(){return FileName;}
};
#include<iostream>
#include<string>
#include"object.h"
#include"reader.h"
using namespace std;
reader::reader():object()
{
sex="";
age=0;
adpartment="";
phone="";
profession="";
address="";
re=" ";
}
reader::reader(int i,string name,string s,
int ag,string a,string ph,string pr,
string ad,string r):object(i,name)
{
sex=s;
age=ag;
adpartment=a;
phone=ph;
profession=pr;
address=ad;
re=r;
}
void reader::SetIndex(int i)
{object::SetIndex(i);}
void SetName(string n)
{object::SetName(n);}
void reader::Setsex(string s)
{sex=s;}
void reader::Setage(int a)
{age=a;}
void reader::Setadpartment(string a)
{adpartment=a;}
void reader::Setphone(string p)
{phone=p;}
void reader::Setprofession(string p)
{profession=p;}
void reader::Setaddress(string a)
{address=a;}
void reader::Setre(string r)
{re=r;}int reader::GetIndex()
{return object::GetIndex();}
string reader::GetName()
{return object::GetName(); }
string reader::Getsex()
{return sex;}
int reader::Getage()
{return age;}
string reader::Getadapartment()
{return adpartment;}
string reader::Getphone()
{return phone;}
string reader::Getprofession()
{return profession;}
string reader::Getaddress()
{return address;}
string reader::Getre()
{return re;}
void reader::Borrowbook(int i)
{
// for
}void reader::giveback(int i)
{}
/////// this is base class ! book class,reader class and librarian class from lllllobject!!
///////Attribute: index,name!
///////operator: Getname,Setname!
///////
///////2004.5.7 zk
///////
//////////////////////////////////////////////////////////////////////////////////////////////////
/*#include<iostream>
#include<string>
using namespace std;
class object
{
private:
int index;
string name;
public:
object();
object(int,string);
// ~object();i can not write code !!so bad!!dont forget it!!
string Getname();
int Getindex();
const object& Getobject();
void Setname(string);
void Setindex(int);
void Setobject(const object);
const object& operator=(const object& );
};
*/
//把头文件改成这样试试#ifndef _OBJECT_H
#define _OBJECT_H#include<iostream>
#include<string>
using namespace std;class object
{
private:
int index;
string name;
public:
object();
object(int,string);
// ~object();i can not write code !!so bad!!dont forget it!!
string GetName(void);
int GetIndex(void);
const object & Getobject(void);
void SetName(string n);
void SetIndex(int);
void Setobject(const object);
const object& operator=(const object& );
};#endif
#include<iostream>
#include<string>
#include"object.h"
using namespace std;object::object()
{
index=-1;
name ="无";
}
object::object(int i,string n):index(i),name(n)
{}
int object::GetIndex(void)
{return index;}
string object::GetName(void)
{return name;}
const object& object::Getobject(void)
{return *this;}
void object::SetIndex(int i)
{index=i;}
void object::SetName(string n)
{name=n;}
void object::Setobject(const object o)
{*this=o;}
const object& object::operator=(const object& o)
{
index=o.index;
name=o.name;
return *this;
}