Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple files program in C++

Status
Not open for further replies.

csripriya1

Programmer
May 13, 2003
35
0
0
US
Hi I am having trouble in programming using multiple files in C++.
I have a class declaration in a header file like this.
class test
{
private:
data;
public:
void testfunc();
}

I included this header in a source file, which gives the definition for those functions in the class in header file.

#include "blahblah.h"

void test::testfunc()
{
.......
}

I am calling a function of this class from main . So, I included this header file in main too.

#include <iostream.h>
#include &quot;blahblah.h&quot;

void main()
{
test justfortest;
.............


justfortest.testfunc();

}
When I am trying to compile this , compiler complains about the functions being declared twice.can anyone pl help me with this.
Thanks for your time.
 
Add include guards to the header.

Code:
#ifndef FILENAME
#define FILENAME

// class definition

#endif
 
As suggested by chipper, go for include guards. They will prevent the double inclusion of the those files. It's because once a header gets included, #define values are set true, so they aren't included the second time when they are looked for.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top