[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

14. What is a method? How is a method called?

Posted on 2015-01-24
3
Medium Priority
?
88 Views
Last Modified: 2015-01-25
14. What is a method? How is a method called?
What is the difference between function and method? How method is stored in memory?
Is it stored in some table as a pointer to function?
0
Comment
Question by:Nusrat Nuriyev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 29

Assisted Solution

by:pepr
pepr earned 2000 total points
ID: 40568145
Class is a (static) description of behaviour of the object of that class. This way "class" can be thoutht of as "kind" of objects. The class (as a description) says how will object also look like from the data point-of-view. If object can be illustrated as a "tangible" entity (say drawn as a circle), data members are smaller circles inside. Better to say, data members are also objects -- we can think about them as about a piece of memory with some content (data) stored inside. However, you have to have access to the data, and you have to know how to interpret them (some numbers mean years, other numbers mean height...).

Methods are member functions of the class. They are also static in the sense of description (one description for any number of objects of that class). If data members (member variables) store values, the member functions (also known as methods) are used for manipulation with the data or for interpretation of the data (i.e. returning something based on the member variables).

Methods are described as a part of a class definition. Typically, they are called with the object (instance of the class) as a standard argument. However, the argument uses a special syntax when the method is called -- the object identifier is written in front of the metod identifier separated by dot (or by -> if pointer to the object is used).

It would be better if you read some decent textbook first and if you asked only the things that you do not understand. Have a look, for example, at "Thinking in C++" by Bruce Eckel (http://mindview.net/Books/TICPP/ThinkingInCPP2e.html -- can also be downloaded for free, or you can by the paper books.)
0
 

Author Comment

by:Nusrat Nuriyev
ID: 40568966
Did you mean that from the description perspective of view methods or data are described more or less similar?
Thank you for the link. I will keep in mind that.
0
 
LVL 29

Accepted Solution

by:
pepr earned 2000 total points
ID: 40569193
Desctiption of both data structure and of the functionality is part of the class definition and it does not depend on whether the object exists of how many objects exist.

When an object is created, the memory for its (internal) data members is allocated (simplified). But there is no need to allocate anything for methods. The object knows its class and the method definitions are part of the class. In other words, data values are part of the memory footprint of the object. The more objects you created, the more memory will be consumed. On the other hand, no extra memory is needed for methods.

Another point of view, both data and methods (i.e. member functions) belong to the object. However, only data is stored inside of the object. Methods describe only the data transformations. Therefore, they are independent of the actual data values.

Another point of view, data definitions and mentod definitions are part of the class definition -- this way they belong to the class. They also  belong to the object of the class, because the object is described by the class. Data values are known to the object but they are not known to the class (simplified).

If you think about "onion", you think about a class of a vegetable. If you have one onion in your hand, it is the object of the class (even in cases when you do not know it is called "onion". The onion class describes how any onion should look like. It may describe its possible weight, but only the object has the exact weight that can be checked whether it is as it should be.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question