C++。什么是子程序和方法?
我有一个 CPP 硬件需要完成。一个问题是:
1)编写一个子程序(不是方法) void PromptForMovie(Movie & myMovie) .....
2)编写一个方法 void Output(ostream & out);那....
我的问题是子程序和方法到底是什么?其中哪一个表示函数,另一个表示什么?
谢谢
I have a CPP HW to be done. One question is:
1) Write a subprogram (not a method) void promptForMovie(Movie & myMovie) that .....
2) Write a method void output(ostream & out); that ....
My question is what exactly is a subprogram and a method? Which one of them means a function, and what does the other mean?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这些不是 C++ 术语,因此您必须询问您的教授他或她的意思。
在其他 OO 语言中,“方法”通常意味着 C++ 所说的“成员函数”;也就是说,函数是类的成员,并在该类的对象上调用。与“自由函数”形成对比,顾名思义,“自由函数”是一个独立函数,不属于任何类的成员。
我怀疑你的教授的意思是“方法”意味着“成员函数”,子程序意味着一个常规的自由函数。但谁知道呢?我不会用我的成绩打赌。
请你的教授使用规范术语重新表述这个问题。
Those aren't C++ terms, so you'll have to ask your professor what he or she means by them.
In other OO languages, "method" typically means what C++ calls a "member function"; that is, a function that is a member of a class, and is invoked on objects of that class. Constrast with a "free function", which, as the name implies, is a standalone function that is not a member of any class.
I suspect that your professor means "method" to mean "member function", and subprogram to mean just a regular free function. But who knows; I wouldn't bet my grades on it.
Ask your professor to rephrase the question using normative terms.
子程序是一个简单的、老式的、非对象关联的函数。
方法是成员函数(类或实例);课程的一部分。必须使用类作用域或对象作用域来调用它。
A subprogram is a simple, old-fashioned, non-object associated function.
A method is a member function (class or instance); part of a class. It must be called with either class scope or object scope.
方法是成员函数的另一种说法。
A method is another word for member function.
这两个术语非常重叠,您需要与您的教授澄清它们,但这是定义它们的一种方式
Both the terms are very overlapping and you need to clarify with your prof about them, but this is a way they can be defined