{"id":1575,"date":"2011-03-08T23:01:46","date_gmt":"2011-03-08T23:01:46","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=1575"},"modified":"2011-06-07T09:45:46","modified_gmt":"2011-06-07T08:45:46","slug":"function-vs-method","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2011\/03\/08\/function-vs-method\/","title":{"rendered":"Function vs Method"},"content":{"rendered":"<p>The main difference between a function and a method is that a function can live independently of the any instance of a class, where as a method sits within a class.<\/p>\n<p>That is about it, e.g. a function is<\/p>\n<pre lang=\"cpp\">\r\nint func(int value);\r\n...\r\n\r\nint main()\r\n{\r\n  cout << funct(3) << endl;\r\n}\r\n<\/pre>\n<p>whereas a method has to live within a class<\/p>\n<pre lang=\"cpp\">\r\nclass myclass\r\n{\r\n    int myMethod(int it);\r\n};\r\n\r\n....\r\n\r\nint main()\r\n{\r\n   myclass theclass;\r\n   cout << theclass.myMethod(4) << endl;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The main difference between a function and a method is that a function can live independently of the any instance of a class, where as a method sits within a class. That is about it, e.g. a function is int func(int value); &#8230; int main() { cout<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[65,330],"class_list":["post-1575","post","type-post","status-publish","format-standard","hentry","category-c_and_cpp","tag-function","tag-method"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=1575"}],"version-history":[{"count":3,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1575\/revisions"}],"predecessor-version":[{"id":1617,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1575\/revisions\/1617"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=1575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=1575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=1575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}