hi everybody
i m writing a simple function void show in c or c++ here is the the definition of the function
void show()
{
cout<<" hi this is test";
}
in case o c function i just use printf in place of cout. i know that the function is doing nothing much.
now just for learning or experimentation purpose i just want to know
how to make header file for this function? and than making library for this function ? so that next time i just include the header file and use this function please explain me completely how to do this
Do you mean a prototype method? A prototype method can be defined like this within a header:
1 2 3 4 5 6 7 8 9 10
#ifndef PROTO_METHOD_H
#define PROTO_METHOD_H
// Proto_method.h
// This is your prototype method. This will need to be defined within the
// included source file.
void show( void ); // Note that the void doesn't have to be there.
#endif
This is the source file where the method is defined.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include "Proto_method.h"
// By including the above header, we have just included the prototype
// of show( ). Now, we need to define it's body.
void show( void )
{
cout << "This is a sample line.\n";
}
// Rest of your source code here...
int main( )
{
show( );
}
This is how you would do it within in a library project.
You can define the method within the header if you wanted to, like this:
1 2 3 4 5 6 7 8 9
#ifndef PROTO_METHOD_H
#define PROTO_METHOD_H
void show( void )
{
cout << "This is a sample line.\n";
}
#endif