读书人

大家帮小弟我看看这个编译链接出现的有

发布时间: 2013-01-17 10:28:54 作者: rapoo

大家帮我看看这个编译链接出现的问题


#include <string>
#include <cstddef>
#ifndef ITEM_BASE_H
#define ITEM_BASE_H
class Item_base
{
public:
Item_base(): price(0.0), count(0) {}
Item_base(double, std::size_t, const std::string&);
virtual Item_base* clone() const
{ return new Item_base(*this); }
virtual double TotlePrice(std::size_t sold)
{ return price * sold; }
std::string& GetBook()
{ return isbn; }
private:
size_t count;
std::string isbn;
double price;
};
#endif



#include "Item_base.h"
#include <string>
#include <cstddef>

Item_base::Item_base(double BookPrice, std::size_t sold, const std::string &BookName):
price(BookPrice), count(sold), isbn(BookName) {}



#include "Item_base.h"
#include <string>
#include <cstddef>
#ifndef BULK_ITEM_H
#define BULK_ITEM_H
class Bulk_item : public Item_base
{
public:
Bulk_item(): Item_base() {}
Bulk_item(double, std::size_t, const std::string&);
Bulk_item* clone() const
{ return new Bulk_item(*this); }
double TotlePrice(std::size_t);
};
#endif



#include "Bulk_item.h"
#include "Item_base.h"
#include <string>
#include <cstddef>

Bulk_item::Bulk_item(double BookPrice, std::size_t sold, const std::string &BookName):
Item_base(BookPrice, sold, BookName) {}

double Bulk_item::TotlePrice(std::size_t sold)
{
double totle = Item_base::TotlePrice(sold);
if (sold <= 5)
return totle * 0.8;
else if (sold > 5 && sold <= 10)
return totle * 0.7;
else if (sold > 10 && sold <= 20)
return totle * 0.6;
else
return totle * 0.5;
}



#include "Item_base.h"
#include "Bulk_item.h"
#include <iostream>
#include <string>
#include <cstddef>
using namespace std;
int main()
{
Bulk_item book1(38.0, 100, "My Class");
Item_base book2(28.0, 50, "C++ Primer");
cout << "本店有两种书出售,1、My Class(38元/本);\n2、C++ Primer(28元/本),你要买哪一本?" << endl;
while (true)
{
cout << "请选择你想要的书以及数量(换行输入数量):" << endl;
string BookName;
getline(cin, BookName);
size_t sold;
cin >> sold;
if (BookName == book1.GetBook())
cout << "你买的书是:" << book1.GetBook()
<< "总价:" << book1.TotlePrice(sold) << endl;
else if (BookName == book2.GetBook())
cout << "你买的书是:" << book2.GetBook()
<< "总价:" << book2.TotlePrice(sold) << endl;
else {
cout << "你的输入有误,请重新输入!" << endl;
continue;
}
cout << "还想继续购买吗?(继续请输入y)" << endl;


char GoOn;
cin >> GoOn;
if (GoOn != 'y')
break;
}
return 0;
}



出错提示:
1>Debug\Item_base.obj : warning LNK4042: 对象被多次指定;已忽略多余的指定
1>Bulk_item.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall Item_base::Item_base(double,unsigned int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0Item_base@@QAE@NIABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z),该符号在函数 "public: __thiscall Bulk_item::Bulk_item(double,unsigned int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0Bulk_item@@QAE@NIABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 中被引用
1>main.obj : error LNK2001: 无法解析的外部符号 "public: __thiscall Item_base::Item_base(double,unsigned int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0Item_base@@QAE@NIABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>c:\users\administrator\documents\visual studio 2010\Projects\work\Debug\work.exe : fatal error LNK1120: 1 个无法解析的外部命令
1>
1>生成失败。
5个文件,按照楼主给的一个个创建,编译没问题。win32控制台应用程序。

读书人网 >C++

热点推荐