| | |
writing a class without the class declaration?
![]() |
•
•
Join Date: Oct 2004
Posts: 6
Reputation:
Solved Threads: 0
hi i am having trouble understanding that what is the difference between having class xxx { } in the .h file and not having it?
say i have these two code, can anyone tell me the difference?
and
say i have these two code, can anyone tell me the difference?
C++ Syntax (Toggle Plain Text)
#ifndef sample_h #define sample_h class sample { function1 (); function2 (); }; #endif
and
C++ Syntax (Toggle Plain Text)
#ifndef sample_h #define sample_h function1 (); function2 (); #endif
Er, well, one has a class definition with two member functions, and one has two functions.
All things being equal, the difference is that you can directly call the two functions in the second case, but need to create an instance of class 'sample' to call the functions in the first case.
The sample class you've defined here doesn't do much 'extra' that classes can be fantastic for. Like, instance variables or constructors/destructors or superclasses.
All things being equal, the difference is that you can directly call the two functions in the second case, but need to create an instance of class 'sample' to call the functions in the first case.
The sample class you've defined here doesn't do much 'extra' that classes can be fantastic for. Like, instance variables or constructors/destructors or superclasses.
The two different implementations can acheive the same results, but they belong to two different familes. One is strucutural and you'll find the C implementations like that (although it does work in C++ as well).
Where as classes are part of C++, which applies Object Oriented approach to solve the problems. In C++, the concept is like, you implement the algorithms in terms of class member functions and these can be accessed through the object (instance) of the class. (for static methods, you don't need the object of the class). This approach gives you good abstraction, encapsulations of data and many other benefits.
There is another pradigm, referred as Generic Programming, where the implementations are done through templates (like STL).
Where as classes are part of C++, which applies Object Oriented approach to solve the problems. In C++, the concept is like, you implement the algorithms in terms of class member functions and these can be accessed through the object (instance) of the class. (for static methods, you don't need the object of the class). This approach gives you good abstraction, encapsulations of data and many other benefits.
There is another pradigm, referred as Generic Programming, where the implementations are done through templates (like STL).
Regards,
Ejaz.
Ejaz.
![]() |
Similar Threads
- Read class from another class (Java)
- problem with class and sub-class (C++)
- pass an interger from one class to others class (Java)
- Accessing a method from class 1 in class 3 (C++)
- Difference between a Template Class and a Class Template (C++)
- Java Class Class problem (Java)
- Class in a class... (Java)
- Confused writing a Java Class (Java)
Other Threads in the C++ Forum
- Previous Thread: redefinition error please help
- Next Thread: loop problem
| Thread Tools | Search this Thread |
action api array auto based beginner binary bitmap c++ c/c++ calculator challenge char class classes code coding compile console conversion count createcopyofanyfileinc delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game garbage givemetehcodez graph gui hmenu homeworkhelp homeworkhelper iamthwee ifstream input insert int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node noob output parameter pointer primenumbersinrange problem program programming project python random read recursion reference rpg sockets string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets





