xtggstc 2022-03-30 20:21 采纳率: 100%
浏览 40
已结题

为什么main函数里b.print()会出错?

为什么main函数里b.print()会出错?

img

#include <iostream>
#include <string>
using namespace std;
class netuser {
private:
    string id, email, code;
    
public:
    netuser() {
        this->id = "无名氏";
        this->code = "出错啦";
        this->email = id + "@gpnu.edu.cn";
        ntotalnumber++;
    }
    netuser(string id, int code) {
        this->id = id;
        this->code = code;
        this->email = email;
        
        ntotalnumber++;
    }
    static int ntotalnumber;
    static void printotal();
    void print();
};
 int netuser::ntotalnumber = 0;
 void netuser::printotal() {
     cout << "用户数:" << ntotalnumber << endl;
 }
 void netuser::print() {
     cout << " " << id << " " << code << " " << email << endl;
 }
 int main()
 {
     netuser a( "JJ.Lin", 123);
     a.printotal();
     a.print();
     netuser b();
     b.printtotal();
     b.print();
     return 0;
 }

  • 写回答

2条回答 默认 最新

  • 浪客 2022-03-30 21:07
    关注

    netuser b;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 3月31日
  • 已采纳回答 3月31日
  • 创建了问题 3月30日

悬赏问题

  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型