恩恩,我又来提问了

小白在此 小白在此 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include <iostream>
#include <stdio.h>
using namespace std;
class Time
{
public:
Time(int h=1,int m = 2,int s = 3)
{
hour = h;
minute = m;
second = s;
}
void set_time();
friend void show_time(Time&);
private:
static int p;
int hour;
int minute;
int second;
};
int Time::p = 12;

int main()
{
Time st1(12,46,23);
Time st2(st1);
show_time(st2);
cout << Time::p << endl;
cout << st1.p << endl;
cout <<st2.p << endl;
return 0;
}

void show_time(Time &t)
{
cout << t.hour << ":" << t.minute << ":" << t.second << endl;
}


将static int p;放在私有区就报错,放在共有区就行,我用的是mingw编译器,是codeblocks自带的,但是用vs2012就不会报错,能解决吗
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
小白在此
C++ 语言 65,214 成员 250,514 内容