0

What is the difference between a method and an object?

Isn't this a method?

void Standard::print_results()

What denotes an object?? CONFUSED!

4
Contributors
4
Replies
5
Views
13 Years
Discussion Span
Last Post by letmec
0
#include <iostream>

class type
{
   int data;
public:
   type(int initializer = 0) : data(initializer) {}
   void method()
   {
	  std::cout << "data = " << data << std::endl;
   }
};

int main()
{
   type object(42);
   object.method();
   return 0;
}

/* my output
data = 42
*/
0

What is the difference between a method and an object?

Isn't this a method?

void Standard::print_results()

What denotes an object?? CONFUSED!

In your example print_results is the method. You then define an object of type Standard in order to be able to use this method on that object.

0

Object is in simple a user-defined data-type.
Methods are different properties of an object.

for example:

char String[30]='DFDFGDFG";

The above definition shows that 'String' is an object of pre-definied data-type char.
And what about methods? Know if want to add two strings then will not use
str3=str1+str2 directly, but you use strcopy(str3,str1); strcat(str3,str2);

Therefore strcat() & strcopy() are the methods or properties.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.