我写了一个包含类定义的头文件
#ifndef STOCKOO_H_
#define STOCK00_H_
#include////
using namespace std;
class Stock
{
private:
string company;
long shares;
double share_val;
double total_val;
void set_tot()
{
total_val = shares*share_val;
}
public:
void acquire(const 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
#include"cppstock00.h"
using namespace std;
void Stock::acquire(const string &co, long n, double pr)
{
company = co;
if (n < 0)
{
cout << "number of shares cant be negative;"
<< company << "shares set to 0.\n";
shares = 0;
}
else
shares = n;
share_val = pr;
set_tot();
}
void Stock::buy(long num, double price)
{
if (num < 0)
{
cout << "numbers of shares purchased cant be negative";
}
else
{
shares += num;
share_val = price;
set_tot();
}
}
void Stock::sell(long num, double price)
{
if (num < 0)
{
cout << "number of shares sold cant be negative.";
}
else if (num>shares)
{
cout << "you cant sell more than you have.";
}
else
{
shares -= num;
share_val = price;
set_tot();
}
}
void Stock::update(double price)
{
share_val = price;
set_tot();
}
void Stock::show()
{
cout << "company:" << company
<< "shares:" << shares << endl
<< "share price:" << share_val
<< "total" << total_val << endl;
}
编译后报错
无法解析的外部命令
无法解析的外部符号
小白求教这是怎么回事[捂脸]