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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using multiple files in C++

Status
Not open for further replies.

csripriya1

Programmer
May 13, 2003
35
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.
I posted this in unix forum too.am sorry for that
 
try this
Code:
#ifndef testlib
#define testlib
//your code here
#endif

That way your class definition will only be processed once


WR
 
Thanks tokra, it worked. sorry for the delay in replying
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top