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

Header Files

Status
Not open for further replies.

benaam

Programmer
Jan 11, 2001
20
US
My A.cpp is
#include "A.h"
writeFile() {
cout<<&quot;hello&quot;<<endl;
}
and in A.h I defined writeFile as a static method.

Now in my B.cpp goes as follows:

#include &quot;A.h&quot;;
int main() {
A::wirteFile();
}

I put all the header files and .cpp files in the same directory. When i am running it on WinNT its working
fine. But when I am running it on solaris using g++ I am getting an error.
When i say
g++ B.cpp
it gives an error undefined symbol writeFile. What can be the error? What should be the directory structure
I should follow when putting my header files and .cpp files?

Thanx in Advance
 
The way I was taught to make a header file was to put the initial declarations in then call the &quot;.cpp&quot; file. For example:
Code:
class A { 
   private: 
   static char *ca1; 
   static char *ca2; 

   static void readFile(void); 
   static string wirteFile(void); 

} 

#include &quot;A.cpp&quot;

A.CPP would look like
Code:
class A { 
   private: 
   static char *ca1; 
   static char *ca2; 

   static void readFile(void); 
   static string wirteFile(void); 

} 

char* A::ca1 = new char[10]; 
char* A::ca2 = new char[10]; 

void readFile() { 
   cout<<&quot;hello&quot;; 
} 

void writeFile() { 
    cout<<&quot;hello&quot;; 
}

You don't include the A.h in the cpp file but you create another file that calls the header file. For example, Main.CPP
Code:
#include &quot;A.h&quot;
int main()
{
   A::writeFile()
}

Your B.CPP could then call A.CPP the way you do it now.


James P. Cottingham
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top