首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

.already defined in.obj什么情况?解决方案

2013-10-11 
...already defined in....obj什么情况?本帖最后由 u011873969 于 2013-10-08 03:32:22 编辑写了这样的两

...already defined in....obj什么情况?
本帖最后由 u011873969 于 2013-10-08 03:32:22 编辑 写了这样的两个代码:

这个叫做Sales_item.h


#include <iostream>
#include <string>

using std::string;
using std::cin;
using std::cout;
using std::endl;

class Sales_item
{
public:
// operations on Sales_item objects
double avg_price() const;
bool same_isbn(const Sales_item &rhs) const
{return isbn == rhs.isbn;}
// an equivalent way to defien this function is as follows:
// {return this->isbn == rhs.isbn;}

// read the items stored in Sales_item
void read_item();

// default constructor needed to initialize members of built-in type
Sales_item(): units_sold(0), revenue(0.0){}


// private members as before
private:
string isbn;
unsigned units_sold;
double revenue;
};


以及这个名叫
Bookstore.cpp


//
#include "Sales_item.h"


void keep_window_open();

int main()
{
Sales_item sale_one;

sale_one.read_item();
keep_window_open();
}

void keep_window_open()
{
cout << "\nPress any key to exit:";
getchar();
}

void Sales_item::read_item()
{
cout<<"\nThis is the items of your current Sales_item:\n";

cout<<"Its ISBN number:\t"<<isbn<<"\n"
    <<endl<<"and "<< units_sold<<"  of it has been sold.\n"
<<"For now, we have earned "<<revenue<<" $ in total!\n";
}

double Sales_item::avg_price() const
{
if(units_sold)
return revenue/units_sold;
else
return 0;
}


可是运行Bookstore.cpp的时候,报错,说....already defined in ....obj,即使把文件夹里除了代码以外的东西都删了也没用。这个是怎么回事呢? class
[解决办法]
你为什么把错误信息里最关键的东西给...了……
[解决办法]
re-build
[解决办法]
引用:
Quote: 引用:

你为什么把错误信息里最关键的东西给...了……


名字太长,也不好打。话说应该是很经典的问题啊。我把代码都给出来了,可以直接复制运行了吧。


代码没有问题,应该是环境问题。 

热点排行