Thursday, July 30, 2009

What is the main difference and advantage of using a class ratther than a function in c++?

i cant understand why we use classes, they appear simiar to functions..what are the advantages of using a class compared to just a function?

What is the main difference and advantage of using a class ratther than a function in c++?
Classes are for object oriented programming which is a different way of thinking about processing. Objects were invented as a way to make complex programming simpler. Yes, object methods are just like functions but you need to learn more about OOP to appreciate classes.





In C, you build your data structures and pass them along to functions with operands to have something happen to them. Bugs show up when you change the datastructure and not all the functions to deal with the new data structure.





In C++, you can build a class that becomes an object and everything, the data structure and the code to operate on that data structure ends up being close together and in theory more maintanable.





An systems architect can farm out the development of classes/objects and have better success of putting it all together than traditional C code.





There are exceptions and pro's and con's to traditional third gen langugaes and OOP languages.





Apache web server is written in C and is a great program. Most GUI things (window managers, applications) are written using the model/view/controller pattern and are OOP languages like Java and C++.





Keep reading.
Reply:A Class defines an object that can be instanciated and manipluated with it's defined methods and properties.





A function is a subroutine that returns a value
Reply:A class gives a way of grouping logical parts of code, including functions. So functions are part of classes. So you can't really discuss the advantages and disadvantages of each.





In procedural programming (using languages like C), functions are king. Your quesion should then be, "What are the advantages and disadvantages of object-oriented programming versus procedural programming."
Reply:they are not the same. a function is just an action, a piece of code that does something. A Class is so much more, it is a data type that you create and it has functions associated with it.. but it is not similar to a function

snow of june

No comments:

Post a Comment