namespace-error C2248: 'Num' : cannot access private ......

问题描述

error C2248: 'Num' : cannot access private ......

#include
#include
#include
#include
using namespace std;
class worker{
string Num; //职工号
string Nam; //姓名
string Pen; //性别
int Age; //年龄
double Sal; //工资
public:
worker(string="#",string="#",string="#",int=0,double=0);
friend ostream & operator<<(ostream & dist,worker & iv); //重载插入运算符
friend istream & operator>>(istream & sour,worker & iv); //重载提取运算符
bool operator==(worker &);
bool operator<=(worker &);
};
worker::worker(string num,string nam,string pen,int age,double sal){
Num=num;
Nam=nam;
Pen=pen;
Age=age;
Sal=sal;;
}
ostream & operator<<(ostream & dist,worker & iv){
dist<
dist
return dist;
}
istream&operator>>(istream & sour,worker & iv){
if(sour==cin){
cout<<"请输入职工号"<
sour>>iv.Num;
cout<<"请输入姓名"<
sour>>iv.Nam;
cout<<"请输入性别"<
sour>>iv.Pen;
cout<<"请输入年龄"<
sour>>iv.Age;
cout<<"请输入工资"<
sour>>iv.Sal;
}
else sour>>iv.Num>>iv.Nam>>iv.Pen>>iv.Age>>iv.Sal;
return sour;
}
bool worker::operator==(worker & wor){return Num==wor.Num;}
bool worker::operator<=(worker & wor){return Num<=wor.Num;}
template
class Array
{
T*elements;
int Subscript;
int maxSize;
fstream datafile;
public:
Array(int=2); //为了便于检验,默认元素数暂时为2
~Array();
bool IsFull()const{return Subscript==maxSize-1;}
void renews(); //内存扩大一倍
void show(){
cout<<"已用最大下标值"<
}
void ordinsert(T&); //输入时以职工号为关键字
friend ostream&operator
};
templateArray::Array(int maxs){
maxSize=maxs;
Subscript=-1; //私有数据不允许直接赋初值,必须在构造函数中赋初值
T temp;
elements=new T[maxSize];
datafile.open("mydatafile.txt",ios::in); //如文件不存在,则打开失败
if(!datafile==0){
while(!datafile.eof()){
datafile>>temp;
if(datafile.eof()==0){ //读到无数据可读后,即读入不成功,eofbit为1
ordinsert(temp); //即使原文件未排序,退出时也安排好序的重存
}
}
datafile.close(); //必须放此处,打开成功才能关闭
}
datafile.clear(0); //前面曾经读到文件结束或文件打开失败,流无法恢复
}
templateArray::~Array(){
int i;
datafile.open("mydatafile.txt",ios::out);
for(i=0;i<=Subscript;i++)datafile<
datafile.close();
delete[ ]elements;
}
templatevoid Array::renews(){
int i;
T*temp=elements;
maxSize*=2;
elements=new T[maxSize];
for(i=0;i<=Subscript;i++) elements[i]=temp[i];
delete[ ]temp;
}
templatevoid Array::ordinsert(T & elem){ //输入时以职工号为关键词
int i;
if(IsFull())renews();
for(i=0;i<=Subscript;i++)if(elem<=elements[i])break;
if(!(elem==elements[i])){
Subscript++;
}
elements[i]=elem;
show();
}
templateostream&operator<<(ostream&dist,Array&ar){
int i;
for(i=0;i<=ar.Subscript;i++) cout<
return dist;
}
int main(){
Arraymylist;
worker temp;
char ch;
cout<<"是否输入新的职工记录?Y or N"<
cin>>ch;
while(ch=='Y'||ch=='y'){
cin.get();
cin>>temp;
mylist.ordinsert(temp);
cout<<"是否继续输入?Y or N"<
cin>>ch;
}
cout<<mylist;
return 0;
}

报错:
c:usersadministratordesktopss.cpp(28) : error C2248: 'Num' : cannot access private member declared in class 'worker'
c:usersadministratordesktopss.cpp(8) : see declaration of 'Num'
c:usersadministratordesktopss.cpp(28) : error C2248: 'Nam' : cannot access private member declared in class 'worker'
c:usersadministratordesktopss.cpp(9) : see declaration of 'Nam'
c:usersadministratordesktopss.cpp(28) : error C2248: 'Pen' : cannot access private member declared in class 'worker'
c:usersadministratordesktopss.cpp(10) : see declaration of 'Pen'
c:usersadministratordesktopss.cpp(29) : error C2248: 'Age' : cannot access private member declared in class 'worker'
c:usersadministratordesktopss.cpp(11) : see declaration of 'Age'
c:usersadministratordesktopss.cpp(29) : error C2248: 'Sal' : cannot access private member declared in class 'worker'
c:usersadministratordesktopss.cpp(12) : see declaration of 'Sal'
c:usersadministratordesktopss.cpp(35) : error C2248: 'Num' : cannot access private member declared in class 'worker'
c:usersadministratordesktopss.cpp(8) : see declaration of 'Num'
c:usersadministratordesktopss.cpp(37) : error C2248: 'Nam' : cannot access private member declared in class 'worker'
c:usersadministratordesktopss.cpp(9) : see declaration of 'Nam'
c:usersadministratordesktopss.cpp(39) : error C2248: 'Pen' : cannot access private member declared in class 'worker'
c:usersadministratordesktopss.cpp(10) : see declaration of 'Pen'
c:usersadministratordesktopss.cpp(41) : error C2248: 'Age' : cannot access private member declared in class 'worker'
c:usersadministratordesktopss.cpp(11) : see declaration of 'Age'
c:usersadministratordesktopss.cpp(43) : error C2248: 'Sal' : cannot access private member declared in class 'worker'
c:usersadministratordesktopss.cpp(12) : see declaration of 'Sal'
c:usersadministratordesktopss.cpp(45) : error C2248: 'Num' : cannot access private member declared in class 'worker'
c:usersadministratordesktopss.cpp(8) : see declaration of 'Num'
c:usersadministratordesktopss.cpp(45) : error C2248: 'Nam' : cannot access private member declared in class 'worker'
c:usersadministratordesktopss.cpp(9) : see declaration of 'Nam'
c:usersadministratordesktopss.cpp(45) : error C2248: 'Pen' : cannot access private member declared in class 'worker'
c:usersadministratordesktopss.cpp(10) : see declaration of 'Pen'
c:usersadministratordesktopss.cpp(45) : error C2248: 'Age' : cannot access private member declared in class 'worker'
c:usersadministratordesktopss.cpp(11) : see declaration of 'Age'
c:usersadministratordesktopss.cpp(45) : error C2248: 'Sal' : cannot access private member declared in class 'worker'
c:usersadministratordesktopss.cpp(12) : see declaration of 'Sal'
c:usersadministratordesktopss.cpp(123) : error C2593: 'operator >>' is ambiguous

解决方案

pricvaye变量不能访问,用public改成

解决方案二:

class worker{
public: //加上这个
...

时间: 2024-11-08 19:41:42

namespace-error C2248: &amp;#39;Num&amp;#39; : cannot access private ......的相关文章

请求-求助啊!!var id=$(this).attr(&amp;amp;#39;id&amp;amp;#39;); 和 $(this).empty(); 怎么结合

问题描述 求助啊!!var id=$(this).attr('id'); 和 $(this).empty(); 怎么结合 已经获得各个id ... $(document).ready(function(){ $('div').click(function(){ var id=$(this).attr('id'); alert(id); //可以得到某个id的值 var aurl=""<%=basePath%>/colV.action""; var ada

javascript-jquery如何设置一个动态创建的 $(&amp;amp;#39;#&amp;amp;#39;).append(&amp;amp;#39;&amp;amp;#39;)中的ID?并利用它

问题描述 jquery如何设置一个动态创建的 $('#').append('')中的ID?并利用它 就比如像这样的: <script type="text/javascript"> var number=0; function next(){ $('#showdata').append('<input class="number_showdata" id="showdataid'+number+'" type="tex

c++基础-error: no match for &amp;amp;#39;operator[]&amp;amp;#39;

问题描述 error: no match for 'operator[]' 很简单的程序,只是使用了函数 定义部分 int a[500],e[500]; 然后下面所有尝试对a数组进行操作的全部报错 a[p]=0; a[p]++;等 错误提示: rror: no match for 'operator[]' (operand types are 'QCoreApplication' and 'int') a[p]++; ^ 而且奇怪的是相同的e数组却没有错误提示(或者将a数组改掉之后就会出现错误提

Error:(108) No resource identifier found for attribute &amp;#39;style&amp;#39; in package &amp;#39;android&amp;#39;

Error:(108) No resource identifier found for attribute 'style' in package 'android'  解决方案: 这是错误的写法: android:style="?android:attr/progressBarStyleHorizontal" /> 去掉android:这个namespace就行了   正确写法如下: style="?android:attr/progressBarStyleHoriz

syntax error, unexpected &amp;amp;#39;(&amp;amp;#39;, expecting &amp;amp;#39;,&amp;amp;#39; or &amp;amp;#39;;&amp;amp;#39;

问题描述 syntax error, unexpected '(', expecting ',' or ';' <?php class HomeAction extends Action { var $link=mysql_connect('hdm14001594.my3w.com','hdm14001594','677kx3930'); if($link){ public function _empty(){ //show 404 page } } } ?> 解决方案 类下面必须是属性或方法

php-syntax error, unexpected &amp;amp;#39;id&amp;amp;#39; (T_STRING)

问题描述 syntax error, unexpected 'id' (T_STRING) $id 上面存在应该没有问题 解决方案 你网页中传进来的querystring里面是否包含id这个参数? 解决方案二: 你的 id=<?php echo $id;?> 那个$id变量后的都好是不是搞成中文状态下的了?

c转换c++-error C2632: &amp;amp;#39;char&amp;amp;#39; followed by &amp;amp;#39;char&amp;amp;#39; is illegal

问题描述 error C2632: 'char' followed by 'char' is illegal 把原来的C文件中的函数封装成一个类成员函数,在.h头文件中.运行就提示一些错误,不知道怎么解决. c:program filesmicrosoft sdkswindowsv7.0aincludewindef.h(154): error C2632: 'char' followed by 'char' is illegal 3>c:program filesmicrosoft sdkswi

php-PHP上传文件的问题$_FILES[&amp;amp;#39;file&amp;amp;#39;][&amp;amp;#39;error&amp;amp;#39;]

问题描述 PHP上传文件的问题$_FILES['file']['error'] 这段时间一直在啃<Head First PHP & MySQL>,这本书非常好,一步步教授怎么开发一个 PHP网站,一直照着一步步地敲代码,现在看到487页,在测试上传文件功能时,发现前面 的editprofile.php里面的 if ($_FILES['file']['error'] == 0) { 老是报错: // Validate and move the uploaded picture file,

MS SQL Could not obtain information about Windows NT group/user &amp;#39;domain\login&amp;#39;, error code 0x5. [SQLSTATE 42000] (Error 15404)

最近碰到一个有趣的错误:海外的一台数据库服务器上某些作业偶尔会报错,报错信息如下所示: ------------------------------------------------------------------------------------------------------------------------------------------------- 日期 2013/9/15 12:00:00 日志 作业历史记录 (JOB_SYNCHRONIZING_ESCM_DATA