![]() |
|
#1
|
|||
|
|||
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:
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
|
|||
|
|||
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
|
|||
|
|||
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:
However when the class body is written it is done like this.. CPP / C++ / C Code:
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
|
|||
|
|||
Re: Classes and its functions.Quote:
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 GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The