vs2013编译数据隐藏文件时第一次运行没错误,第二次就提示无法解析的外部符号

baidu_35219145 2016-06-04 04:30:50
源程序
#include <iostream>
#include "stock.h"
int main()
{
Stock flu;
flu.acquire("Nanosmart", 20, 12.50);
flu.show();
flu.buy(15, 18.125);
flu.show();
flu.sell(400, 20.00);
flu.show();
flu.buy(300000, 40.125);
flu.show();
flu.sell(300000, 0.125);
flu.show();
return 0;
}
头文件
#ifndef STOCK_H_
#define STOCK_H_

#include <string>

class Stock
{
private:
std::string company;
long shares;
double share_val;
double total_val;
void set_tot(){ total_val = shares*share_val; }
public:
void acquire(const std::string &co, long n, double pr);
void buy(long num, double price);
void sell(long num, double price);
void update(double price);
void show();
};

#endif

定义头文件
#include <iostream>
#include "stock.h"

void Stock::acquire(const std::string &co, long n, double pr)
{
company = co;
if (n < 0)
{
std::cout << "数值不能为零 "
<< company << "低于零\n";
shares = 0;
}
else
shares = n;
share_val = pr;
set_tot();
}

void Stock::buy(long num, double price)
{
if (num < 0)
{
std::cout << "数值不能为零 \n";
}
else
{
shares += num;
share_val = price;
set_tot();
}
}

void Stock::sell(long num, double price)
{
using namespace std;
if (num < 0)
{
cout << "数值不能为零 \n";
}
else if (num>shares)
{
cout << "数值超额\n";
}
else
{
shares -= num;
share_val = price;
set_tot();
}
}

void Stock::update(double price)
{
share_val = price;
set_tot();
}

void Stock::show()
{
std::cout << "company:" << company
<< "shares:" << shares
<< "share price:$:" << share_val
<< "total worth:$:" << total_val << std::endl;
}
...全文
93 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
小灸舞 2016-06-04
  • 打赏
  • 举报
回复
重建工程试试
paschen 版主 2016-06-04
  • 打赏
  • 举报
回复
帮你看了,可以正常编译链接 你看下你CPP文件有没有添加到工程中

64,647

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧