#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
//*********************
class Carlo{
static int number;
static int wei;
static int val;
static int sto;
public:
static void setdate(int weight,int value,int stock);
Carlo(int n)
{
number=n;
wei=100;
val=100;
sto=50;
}
void print()
{
cout<<"商品售出: "<<number;
}
static void showtotal();
};
void Carlo::setdate(int weight,int value,int stock)
{
wei=weight;
val=value;
sto=stock;
cout<<"当前商品总重量为: "<<wei*sto<<"商品总价值为: "<<sto*val<<endl;
}
void Carlo::showtotal()
{
cout<<"当前商品总重量为: "<<wei*sto-number<<"商品总价值为: "<<(sto-number)*val<<endl;
}
//=====================
int main()
{ FILE *fp;
if ((fp=fopen("oop3_4.in","r"))!=NULL)
{freopen("oop3_4.in", "r", stdin);
freopen("oop3_4.out", "w", stdout);
}
int weight,value,stock,n;
Carlo *p;
cout<<"输入货物重量 价格:";
cin>>weight>>value;
cout<<"输入库存数:";
cin>>stock;
cout<<"输入商品买卖信息:";
cin>>n;
Carlo::setdate(weight,value,stock);//要求setdate()为静态成员函数
while(n!=0)
{ p=new Carlo(n);
p->print();
p->showtotal(); //要求showtotal()为静态成员函数
cin>>n;
}
return 0;
}
--------------------Configuration: oop3_4 - Win32 Debug--------------------
Compiling...
oop3_4.cpp
Linking...
oop3_4.obj : error LNK2001: unresolved external symbol "private: static int Carlo::sto" (?sto@Carlo@@0HA)
oop3_4.obj : error LNK2001: unresolved external symbol "private: static int Carlo::val" (?val@Carlo@@0HA)
oop3_4.obj : error LNK2001: unresolved external symbol "private: static int Carlo::wei" (?wei@Carlo@@0HA)
oop3_4.obj : error LNK2001: unresolved external symbol "private: static int Carlo::number" (?number@Carlo@@0HA)
Debug/oop3_4.exe : fatal error LNK1120: 4 unresolved externals
执行 link.exe 时出错. oop3_4.exe - 1 error(s), 0 warning(s)
哪里错了??、
#include <stdio.h>
#include <string>
using namespace std;
//*********************
class Carlo{
static int number;
static int wei;
static int val;
static int sto;
public:
static void setdate(int weight,int value,int stock);
Carlo(int n)
{
number=n;
wei=100;
val=100;
sto=50;
}
void print()
{
cout<<"商品售出: "<<number;
}
static void showtotal();
};
void Carlo::setdate(int weight,int value,int stock)
{
wei=weight;
val=value;
sto=stock;
cout<<"当前商品总重量为: "<<wei*sto<<"商品总价值为: "<<sto*val<<endl;
}
void Carlo::showtotal()
{
cout<<"当前商品总重量为: "<<wei*sto-number<<"商品总价值为: "<<(sto-number)*val<<endl;
}
//=====================
int main()
{ FILE *fp;
if ((fp=fopen("oop3_4.in","r"))!=NULL)
{freopen("oop3_4.in", "r", stdin);
freopen("oop3_4.out", "w", stdout);
}
int weight,value,stock,n;
Carlo *p;
cout<<"输入货物重量 价格:";
cin>>weight>>value;
cout<<"输入库存数:";
cin>>stock;
cout<<"输入商品买卖信息:";
cin>>n;
Carlo::setdate(weight,value,stock);//要求setdate()为静态成员函数
while(n!=0)
{ p=new Carlo(n);
p->print();
p->showtotal(); //要求showtotal()为静态成员函数
cin>>n;
}
return 0;
}
--------------------Configuration: oop3_4 - Win32 Debug--------------------
Compiling...
oop3_4.cpp
Linking...
oop3_4.obj : error LNK2001: unresolved external symbol "private: static int Carlo::sto" (?sto@Carlo@@0HA)
oop3_4.obj : error LNK2001: unresolved external symbol "private: static int Carlo::val" (?val@Carlo@@0HA)
oop3_4.obj : error LNK2001: unresolved external symbol "private: static int Carlo::wei" (?wei@Carlo@@0HA)
oop3_4.obj : error LNK2001: unresolved external symbol "private: static int Carlo::number" (?number@Carlo@@0HA)
Debug/oop3_4.exe : fatal error LNK1120: 4 unresolved externals
执行 link.exe 时出错. oop3_4.exe - 1 error(s), 0 warning(s)
哪里错了??、