473,385 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Confusion over header files

i have a multifile program namely

bpl.cpp-contains main() function
idr.h ( class definitions)
idr.cpp ( the implementation of the functions in the classes described
in idr.h)
bpl1.h ( contains declaration of a global variable)

The code from each file is pasted here,
///////////////////////////////////////////
//bpl1.h

#ifndef BPL1_H
#define BPL1_H

extern char orig_file_name[];

#endif

/////////////////////////////////////////////

//bpl.cpp

#include "idr.h"
#include <string>
#include <iostream>
#include <fstream>
#include <new>
char orig_file_name[40];
using namespace std;
int main(int argc, char *argv[])
{
char** record=NULL ;
record = new char*[26];
for(int c=0; c<26; c++)
{
record[c] = new char[20];
}
char *str;
str= new char[250];
char *str1;
str1 = new char[50];
if(argc!=2)
{
cout<<"usage:";
cout<<argv[0];
return 1;
}
ifstream in(argv[1]);
strcpy(orig_file_name,argv[1]);
if(!in)
{
cout<<"can't open input file.\n";
return 1;
}
while(in)
{

//some file reading/Writing code here
}
idrheader hdr; // declares one object of idr_header type
body ob2; //declare an object of body type
hdr.set_header(ob2); //initialize IDR Header
hdr.write_idr_header(); //write IDR Header to output file
hdr.print_body_head(); //print body head
hdr.append_body(); // append body to the output file
for(int c=0; c<26; c++)
{
delete[] record[c];
}
delete[] record; // free memory occupied by record
delete[] str; // free memory occupied by str
delete[] str1; // free memory occupied by str1
}
///////////////////////////////////////////////////////////////////////////////////////////////////

// idr.h

#ifndef IDR_H
#define IDR_H
#ifndef BODY_CLASS
#define BODY_CLASS
#include "bpl1.h"
#include <time>
#include <string>
#include <iostream>
#include <fstream>

class body
{
private:
friend class idrheader;
static float total_records;
static char FIRST_DTTM[20];
static char LAST_DTTM[20];
static long rec_key_g;
static time_t min_time;
....
....
....//various variables

public:
body();
int prepare_body(char **rec);
int write_body();
int print_body_head();
time_t body::date_parse(char*);

};

float body::total_records; //define total records
int body::rejected_records;
long body::rec_key_g;
char body::FIRST_DTTM[20];
char body::LAST_DTTM[20];
char body::str[80];
time_t body::min_time;
time_t body::max_time;
#endif

#ifndef IDRHEADER_CLASS
#define IDRHEADER_CLASS
// second class definition
class idrheader
{
private:
char IDR_VERSION;
char* SWI_ID;
float FILE_SEQ_NBR;
float TOTAL_RECS;
....
....
....//various variables
public:
idrheader();
void set_header(body b);
int write_idr_header();
int print_body_head();
int append_body();

};
#endif
#endif

///////////////////////////////////////////////////////////////////////
idr.cpp

#include "idr.h"

body::body()
{
// initialize the members
}

int body::prepare_body(char **rec)
{
// do processing on the members and prepare them for final output
}

// this function does the date parsing and format changing
time_t body::date_parse(char st[])
{
//some functioning
}

idrheader::idrheader()
{
//constructor which inititalizes the variables
}

// this is the bone of content pls look this
void idrheader::set_header(body b)
{
TOTAL_RECS=b.total_records; // The number of records counted.
Found in total_records from above.
strcpy(FIRST_DTTM,b.FIRST_DTTM); // The least call time has been
caught earlier. Normally first record.
strcpy(LAST_DTTM,b.LAST_DTTM); // The biggest call time till
now. Normally the lat record.
strcpy(ORIG_FILE_NAME,orig_file_name); // The input file name
SWI_ID="1"; // Switch ID not know. Keeping it 1. Ask
Damien/Antony
REJECTED_RECS=b.rejected_records; // Only info for the time being
DISCARDED_RECS=b.error_records; // Only info for the time being
GEN_FIELD_NAME_1= "operator name"; // These are the general fields
GEN_FIELD_NAME_2= "OP" ;
GEN_FIELD_NAME_3= "";
GEN_FIELD_NAME_4= "";
GEN_FIELD_NAME_5= "";
}

int idrheader::write_idr_header()
{
//some functioning
}

int idrheader::print_body_head()
{

//some functioning

}

int idrheader::append_body()
{
//some functioning
}
//////////////////////
On compiling it does not give any error, but on executing it gives
following error(and many other of similar type)
Error: Error: Unresolved external 'idrheader::write_idr_header()'
referenced from C:\BC5\BIN\DHARMESH\BPL\TEST\BPL.OBJ

Pls Help i am confused ??
Jul 19 '05 #1
5 2748
> i have a multifile program namely

bpl.cpp-contains main() function
idr.h ( class definitions)
idr.cpp ( the implementation of the functions in the classes described
in idr.h)
bpl1.h ( contains declaration of a global variable)

*snip code*
On compiling it does not give any error, but on executing it gives
following error(and many other of similar type)
Error: Error: Unresolved external 'idrheader::write_idr_header()'
referenced from C:\BC5\BIN\DHARMESH\BPL\TEST\BPL.OBJ

Pls Help i am confused ??


Stupid question: is the idr.cpp file added to your makefile/projectfile?

/Nic
Jul 19 '05 #2
ni*@aub.dk (Nicolai Hansen) wrote in message news:<d9*************************@posting.google.c om>...
i have a multifile program namely

bpl.cpp-contains main() function
idr.h ( class definitions)
idr.cpp ( the implementation of the functions in the classes described
in idr.h)
bpl1.h ( contains declaration of a global variable)


*snip code*
On compiling it does not give any error, but on executing it gives
following error(and many other of similar type)
Error: Error: Unresolved external 'idrheader::write_idr_header()'
referenced from C:\BC5\BIN\DHARMESH\BPL\TEST\BPL.OBJ

Pls Help i am confused ??


Stupid question: is the idr.cpp file added to your makefile/projectfile?

/Nic


Thanks for ur reply but i am new to g++ pls help how should i add
idr.cpp in my makefile ??

Thanks,
Dharmesh
Jul 19 '05 #3
"John Harrison" <jo*************@hotmail.com> wrote in message news:<bh************@ID-196037.news.uni-berlin.de>...
"dharmesh Gupta" <dh************@esteltelecom.com> wrote in message
news:45**************************@posting.google.c om...
i have a multifile program namely

[snip]
On compiling it does not give any error, but on executing it gives
following error(and many other of similar type)
Error: Error: Unresolved external 'idrheader::write_idr_header()'
referenced from C:\BC5\BIN\DHARMESH\BPL\TEST\BPL.OBJ

Pls Help i am confused ??


At a guess I would say that you forgot to compile the idr.cpp file.
Unfortunately this is not the place to help you operate your compiler, but
somehow or other you must tell you compiler that you want to compile the
idr.cpp file.

i got the mistake. I am using Boreland 5.02 compiler. I think the
compiler is not able to link idr.cpp to the ultimate code, since i am
new to this compiler pls help how should i include this file.

Thanks,
Dharmesh
Also remove the definitions of the static member variables in class body
from idr.h and put them in idr.cpp, e.g.

// this should go in idr.cpp
float body::total_records; //define total records

If you can't get it to work then I would suggest putting *everything* in one
cpp file and one header file, then try moving *one* thing into another cpp
file, and see if you can get that to work. Then try one more thing into
another cpp file. Keep going like that until you are confident you
understand what you are doing.

john

Jul 19 '05 #4
Thanks for ur reply but i am new to g++ pls help how should i add
idr.cpp in my makefile ??


I would use a text editor if I where you.

If you don't know how a makefile works this is an excelent time to do a
web search and learn. You can start by reading
http://www.elitecoders.de/mags/cscene/CS2/CS2-10.html

NR

Jul 19 '05 #5
dh************@esteltelecom.com (dharmesh Gupta) wrote in message news:<45*************************@posting.google.c om>...
ni*@aub.dk (Nicolai Hansen) wrote in message news:<d9*************************@posting.google.c om>...
i have a multifile program namely

bpl.cpp-contains main() function
idr.h ( class definitions)
idr.cpp ( the implementation of the functions in the classes described
in idr.h)
bpl1.h ( contains declaration of a global variable)


*snip code*
On compiling it does not give any error, but on executing it gives
following error(and many other of similar type)
Error: Error: Unresolved external 'idrheader::write_idr_header()'
referenced from C:\BC5\BIN\DHARMESH\BPL\TEST\BPL.OBJ

Pls Help i am confused ??


Stupid question: is the idr.cpp file added to your makefile/projectfile?
i have compiled it using the comand g++ bpl.cpp idr.cpp -o bpl
and run it ./bpl successfully. is this the right way to do it ??
/Nic
Thanks,

Dharmesh

Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Eternally | last post by:
Ok, this may sound confusing....but it's really simple. If you're confused, just look at my example code and it'll make sense. Here's my situation. I have 2 classes....A and B. Class A has a...
16
by: matthurne | last post by:
I just started learning C++ on my own...I'm using Accelerated C++. Something it hasn't explained and I keep wondering about is how header files actually work. I suspect it doesn't get into it...
2
by: puzzlecracker | last post by:
after reading some of the post I found out something rather radical to my previous understanding: that when you do #include<iostream> #include<string> #include<vector> etc compiler puts...
8
by: Roman Töngi | last post by:
I don't yet understand how to divide a C++ project into header and implementation files. The following won't compile: // Apple.cpp #include <iostream> #include "random.h" using namespace std;...
0
by: CW | last post by:
I have run into a lot problems with SSL, and would appreciate some clear explanations: (1) Non-SSL links within SSL pages: In one of my earlier posts, I was having problems with links that...
10
by: joelagnel | last post by:
hi friends, i've been having this confusion for about a year, i want to know the exact difference between text and binary files. using the fwrite function in c, i wrote 2 bytes of integers in...
1
by: Richard Lewis Haggard | last post by:
I'm having a problem with what appears to be some sort of confusion with references. I have a single solution with a dozen projects which has been working quite nicely for a while. The references...
6
by: vivekian | last post by:
Hi, I am not sure if this is a relevant topic here, anyways, When using the std namespace is it a good practice to .. put this right at the beginning using namespace std ;
6
by: przemek | last post by:
I used to think that including header files gives me some extra function to use. Like putting <stdlib.h> allows use of system("PAUSE") without doing anything special. I disovered lately that it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.