为马不能运行??

kurt8276 2004-05-06 03:52:56
#ifndef _OBJECT_H
#define _OBJECT_H


#include<iostream>
#include<string>
using namespace std;

class object{};

class LibraryObject:public object
{
private:
int index;
string name;
public:
LibraryObject();
LibraryObject(int i,string n="无");
LibraryObject(string n);
int GetIndex();
string GetName();

void SetIndex(int );
void SetName(string);
virtual void ShowData();

};
#endif
#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;}
LibraryObject::LibraryObject(string n)
{name=n;}
int LibraryObject::GetIndex()
{return index;}
string LibraryObject::GetName()
{return name;}
void LibraryObject::SetIndex(int i)
{index=i;}
void LibraryObject::SetName(string n)
{name=n;}
void LibraryObject::ShowData()
{cout<<index<<" "<<name<<" "<<endl;}

...全文
16 3 点赞 打赏 收藏 举报
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
aspvbjava 2004-05-06
在book.h文件开头加上下面的
#ifndef __BOOK_H__
#define __BOOK_H__

结尾加上下面的
#end if //__BOOK_H__

试试
  • 打赏
  • 举报
回复
kurt8276 2004-05-06
我该好了!!
可是我对book类稍加改动
就提示说--------------------Configuration: Library - Win32 Debug--------------------
Compiling...
Book.cpp
Librarian.cpp
Library.cpp
d:\library\book.h(13) : error C2011: 'Book' : 'class' type redefinition
LibraryObject.cpp
Reader.cpp
Error executing cl.exe.

Library.exe - 1 error(s), 0 warning(s)
  • 打赏
  • 举报
回复
kurt8276 2004-05-06


#include<iostream>
#include<string>
#include"LibraryObject.h"
using namespace std;

class Book :public LibraryObject
{
private:
string wname;
string pubcomname;
bool state;
string remark;
bool CDROM;
/////
static const char FileName[15];
public:
Book();
Book(int i,string Bookname,string writername,string publishcompany,bool s,bool CDROM=0,string r="");
Book(int i,string Bookname,string writername,string publishcompany,bool s,bool CDROM=0);
//~Book();
void SetIndex(int);
void SetBookname(string);
void Setwritername(string);
void Setpublishcompany(string);
void Setstate(bool);
void SetCDROM(bool);
void Setremark(string);

int GetIndex(void);
string GetBookname(void);
string Getwritername(void);
string Getpublishcompany(void);
bool Getstate(void);
bool GetCDROM(void);
string Getremark(void);

void CheckOut(void);
// static const char *GetFileName(){return FileName;}
};
const char Book::FileName[15]=" Book.txt ";
//const char *Book::GetFileName();
#include<iostream>
#include<string>
#include"LibraryObject.h"
#include"Book.h"
using namespace std;
Book::Book():LibraryObject()
{
wname="无";
pubcomname="无";
state=0;
remark="三无";
CDROM=0;
}
Book::Book(int i,string Bookname,
string writername,string publishcompany,
bool s,bool c,string r):LibraryObject(i,Bookname)
{
wname=writername;
pubcomname=publishcompany;
state=s;
remark=r;
CDROM=c;
}
Book::Book(int i,string Bookname,string writername,
string publishcompany,bool s,bool c):LibraryObject(i,Bookname)
{
wname=writername;
pubcomname=publishcompany;
state=s;
remark="";
CDROM=c;
}
void Book::SetIndex(int i)
{LibraryObject::SetIndex(i);}
void Book::SetBookname(string n)
{LibraryObject::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::Setremark(string r)
{remark=r;}
int Book::GetIndex(void)
{return LibraryObject::GetIndex();}
string Book::GetBookname(void)
{return LibraryObject::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::Getremark(void)
{return remark;}
void Book::CheckOut(void)
{
if (state==0)
throw("Book is not in library!");
state=0;
}
  • 打赏
  • 举报
回复
相关推荐
发帖
VC/MFC
加入

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2004-05-06 03:52
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……