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 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程