为了账号安全,请及时绑定邮箱和手机立即绑定

C++一个错,不会改?

C++一个错,不会改?

C++
灬elliott 2016-06-11 15:15:16
#include <iostream.h>#include <string.h>class CStudent{ friend void SetAge(int age);public:CStudent(char *n, int a);~CStudent(); void SetAge(int age);private:char *name;int age;static int nTotalObj;};int CStudent::nTotalObj = 0;CStudent::CStudent(char *n, int a):age(a){int nLen = strlen(n);name = new char[nLen+1];strcpy(name,n);name[nLen] = '\0';nTotalObj++;}CStudent::~CStudent(){delete[] name;nTotalObj--;}void CStudent::SetAge(int age){this->age = age;}void main(){CStudent stu1("张三",25);CStudent str2("李四",26);cout<<"CStudent::nTotalObj="<<CStudent::nTotalObj<<endl;}错误信息:D:\soft\编程软件\Cpp1.cpp(38) : error C2248: 'nTotalObj' : cannot access private member declared in class 'CStudent'
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 1817 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信