GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-Nov-2008, 04:51
spooshah spooshah is offline
New Member
 
Join Date: Oct 2008
Posts: 15
spooshah is an unknown quantity at this point

Classes and its functions.


'Halo World'.

I have a small doubt regarding the classes their definition and use in main.
Here is the scenario.

I have a header file Header.h in which I am defining classes A, B, C...
On the other hand I have many different programs written Program1.C, Program2.C .....

In all the programs I have written #include <Header.h> so as to be able to access the classes and their functions in Header.h. I will be using the functions in the Program1.C in accordance to the syntax which will be A::example( , )

I am linking all the programs together and running the executable. Till this point Everything is sort of clear to me.

But now if I comment the whole class A in the Header.h or suppose I comment only the class name and the opening parenthesis and the closing parenthesis i.e. It would look something like this

CPP / C++ / C Code:
Class A
{
public:
//.....................
private:
//............
}

After doing this I still use the classes and the functions the way I used to.
What would be the output and how would the whole program run.

Please help me out if you can. Will gladly provide anymore information that you may require to crack this.

Thank you.
Last edited by admin : 05-Nov-2008 at 06:19. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #2  
Old 05-Nov-2008, 05:44
cpit cpit is offline
Junior Member
 
Join Date: Jan 2006
Posts: 73
cpit is on a distinguished road

Re: Classes and its functions.


Basically, if you do not have a .h file, you must declare the class before to use it.
On the other hand, with .h file you can call the functions even if it is implemented after the line you are coding.

I hope it help you.
  #3  
Old 05-Nov-2008, 06:01
spooshah spooshah is offline
New Member
 
Join Date: Oct 2008
Posts: 15
spooshah is an unknown quantity at this point

Re: Classes and its functions.


Hi.

First of all thanks for the reply.

The .h File is always there included in the .C programs...
However the classes or the class name and the parenthesis have been commented.

in the .h file the classes and pointers used to access their functions are also defined like this

CPP / C++ / C Code:
#ifndef __CLASSES__
class TReaction;
class TSpecies;
class TProperties;
class TFlame;
class T0DFlame;
class T1DFlame;
struct BoundaryInput;
struct FirstInput;

typedef TReaction *TReactionPtr;
typedef TSpecies *TSpeciesPtr;
typedef TProperties *TPropertiesPtr;
typedef TFlame *TFlamePtr;
typedef T0DFlame *T0DFlamePtr;
typedef T1DFlame *T1DFlamePtr;
typedef BoundaryInput *BoundaryInputPtr;
typedef FirstInput *FirstInputPtr;
#endif // __CLASSES_

However when the class body is written it is done like this..

CPP / C++ / C Code:
//*******************************************
class TReaction
{*/
public:
//.........
protected:
//.......
}

So the thing that is confusing me is that if the class name is commented how can its functions be accessed.
Really don't understand what going on...
Last edited by admin : 05-Nov-2008 at 06:21. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #4  
Old 05-Nov-2008, 09:06
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Classes and its functions.


Quote:
Originally Posted by spooshah
So the thing that is confusing me is that if the class name is commented how can its functions be accessed.
The convention is to put the entire class declaration in a header file such that it can be included in any source code file which needs to access member functions, etc.

Forward references are only of limited value. They only allow pointers to be created. Dereferencing & calling member functions is not allowed because the compiler has no information about what member functions are declared within the class. This is why the entire class declaration is required.

Nevertheless, the linker will still need to be provided all object files & libraries which are required to create the resulting binary/executable.
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:08.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.