标题:VS2015报错问题
只看楼主
hcs_xiaohan
Rank: 2
等 级:论坛游民
帖 子:40
专家分:23
注 册:2016-7-4
结帖率:91.67%
已结贴  问题点数:10 回复次数:2 
VS2015报错问题
程序代码如下:


#include<iostream>
using namespace std;
class Cargo
{
private:
    float weight;
    static int Totalnum;
    static float Totalweight;
public:
    Cargo(float w=0);
    ~Cargo();
    static void print();
};
Cargo::Cargo(float w)
{
    weight = w;
    Totalweight += weight;
    Totalnum++;
}
Cargo::~Cargo()
{
    Totalweight -= weight;
    Totalnum--;
}
void Cargo::print()
{
    cout << "Total weight=" << Totalweight << endl << "Total num=" << Totalnum << endl;
}
int main()
{
    float weight;
    cout << "input weight1:";
    cin >> weight;
    Cargo c1(weight);
    cout << "input weight2:";
    cin >> weight;
    Cargo c2(weight);
    Cargo::print();
    return 0;
}



请问这个是什么错误?
搜索更多相关主题的帖子: include private public 
2016-08-06 11:12
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:10 
提示说得很清楚呀,你还是定义一下吧
int Cargo::Totalnum = 0;
另一个也一样
2016-08-06 12:16
hcs_xiaohan
Rank: 2
等 级:论坛游民
帖 子:40
专家分:23
注 册:2016-7-4
得分:0 
回复 2楼 rjsp
明白了,多谢
2016-08-07 16:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-467603-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038398 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved