调用一个对象 [英] Calling an object
问题描述
这应该是一项非常简单的任务,但它让我适合。自从我上一篇文章以来,我已经取得了一些进展(我认为),请原谅我制作一个新帖子。我有一个程序正在读取文件并创建一个对象数组(如果有人可以通过查看我的代码来验证这个程序实际上是这样做我会很感激)。我有2个课程,你可以在下面看到,我想简单地调用我的displaySin();来自Class Person的功能。我不确定如何从我的主函数调用我想从案例2调用它:我的主程序中的switch语句。我以为它只是Student.displaySin();但事实并非如此。任何帮助总是受到赞赏。另外我知道我的类函数可能有错误,但这不是我的优先级。
This should be a very simple task, but its giving me fits. I have made some progress (i think) since my last post and forgive me for making a new thread. I have a program that is reading in a file and creating an array of objects (if someone could verify that this program is actually doing this just by looking at my code I would appreciate it). I have 2 classes as you can see below and I want to simply call my displaySin(); function from Class Person. I am unsure how to make the call from my main function I want to call it from case 2: of my switch statement in my main program. I thought it would be simply "Student.displaySin();" but it is not. Any help is appreciated at always. Also I am aware there are probably errors in my class function, but that is not my priority atm.
推荐答案
您将无法调用该函数
You will not be able to call the function as
你是对的。但我正在创建学生,所有学生都有不同的罪恶等等....我不知道如何调用这些对象,因为它们存储在一个数组中。
学生[0] .displaySin();是尝试获取这些lil bugger的许多失败尝试之一。
You are correct. But i am creating Students, all of whom have different sin numbers etc.... I have no idea how to call these objects because they are being stored in an array.
Student[0].displaySin(); was one of many failed attempts at tryin to get at these lil buggers.
你好,
一种可能的方法是覆盖派生类中的displaySin():
Hello,
One possible way is to override displaySin() in the derived class:
这篇关于调用一个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!