从函数返回一个数组

从函数返回一个数组

本文介绍了从函数返回一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好。我正在编写一个程序,它接收各种数组的信息。我使用设置输入信息功能。然后我需要从输出函数输出该信息。我在获取信息方面遇到了问题。我想我需要返回一个指向数组开头的指针,虽然我有很多问题。Hello everyone. I am writing a program which takes in information to various arrays. I input the info using "set" functions. I then need to output that info from an output function. I''m having problems getting to the information. I think I need to return a pointer to the beginning of the array, although I''m having alot of problems. 展开 | 选择 | 换行 | 行号推荐答案此代码:This code: void Employee :: output() { int emp; cout<<"您要查看哪位员工的信息?"<< endl; cin>> emp; cout<<"姓氏:"<<< GetLname()<< endl; cout<<"名字:"<<< GetFname()<< endl; cout<<"员工编号:"< ;< Getenumber()<< endl; cout<<" Employee ssn:"<< Getssn()<< endl; }void Employee::output(){ int emp; cout<<"Which employee''s information would you like to view?"<<endl; cin>>emp; cout<<"Last name: "<<GetLname()<<endl; cout<<"First name: "<<GetFname()<<endl; cout<<"Employee number: "<<Getenumber()<<endl; cout<<"Employee ssn: "<<Getssn()<<endl;} 是员工成员函数。您可以访问Per:is an Employee member function. You have access to Per: 展开 | 选择 | Wrap | 行号因此在我的输出函数中我应该通过使用来访问get函数(例如)per.getssn()?我让他们返回零,因为我无法让他们返回正确的值,这是我的故障排除方式,以确保返回一个值。 至于调试器,这是我的第二个c ++类,我的讲师根本没有提到使用它。我计划在下次会议上询问他有关调试器的事。我试图用它...而且真的不明白它发生了什么。 谢谢, JSo within my output function I should be accessing the get functions by using (for example) per.getssn()? I have them returning zero because I couldn''t get them to return the correct value, and it was my way of troubleshooting to ensure that a value was being returned.As for the debugger, this is my second c++ class and my instructor has not mentioned using it at all. I plan to ask him in our next meeting about debugger. I attempted to use it...and really didn''t understand what was going on with it.Thanks,J 所以在我的输出函数中我应该使用(例如)per.getssn()访问get函数?我让他们返回零,因为我无法让他们返回正确的值,这是我的故障排除方式,以确保返回一个值。So within my output function I should be accessing the get functions by using (for example) per.getssn()? I have them returning zero because I couldn''t get them to return the correct value, and it was my way of troubleshooting to ensure that a value was being returned. 这是正确的。您的get函数需要返回类私有数据成员的副本。当类数据成员是一个数组时,这有点困难,因为你不能从函数返回一个数组。 你可以做的是返回数组名:That is correct. Your get functions need to return a copy of the class private data member. This is a little tough when the class data member is an array since you can''t return an array from a function.What you can do is return the array name: 展开 | 选择 | Wrap | 行号 这篇关于从函数返回一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-30 02:07