开发者

C++. What is a subprogram and method?

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


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

  • Subprogram - Its part of your program which achieves a functionality for example a subprogram which stores the performes some computation on data. Now it is up to you how you define such a subprogram. You could implement it as a single monolitic function or a set of functions or maybe using classes.
  • Method - another name for a function
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜