writing a class without the class declaration?

Reply

Join Date: Oct 2004
Posts: 6
Reputation: confusedmind is an unknown quantity at this point 
Solved Threads: 0
confusedmind confusedmind is offline Offline
Newbie Poster

writing a class without the class {} tag

 
0
  #1
Oct 23rd, 2004
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?
  1. #ifndef sample_h
  2. #define sample_h
  3.  
  4. class sample {
  5.  
  6. function1 ();
  7. function2 ();
  8.  
  9. };
  10.  
  11. #endif

and

  1.  
  2. #ifndef sample_h
  3. #define sample_h
  4.  
  5. function1 ();
  6. function2 ();
  7.  
  8. #endif
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 436
Reputation: Chainsaw is an unknown quantity at this point 
Solved Threads: 10
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: writing a class without the class declaration?

 
0
  #2
Oct 24th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 10
Reputation: Ejaz is an unknown quantity at this point 
Solved Threads: 0
Ejaz's Avatar
Ejaz Ejaz is offline Offline
Newbie Poster

Re: writing a class without the class declaration?

 
0
  #3
Oct 24th, 2004
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).
Regards,

Ejaz.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC