Confusion over header files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dharmesh Gupta

    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_fil e_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_h eader(); //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(ch ar **rec);
    int write_body();
    int print_body_head ();
    time_t body::date_pars e(char*);

    };

    float body::total_rec ords; //define total records
    int body::rejected_ records;
    long body::rec_key_g ;
    char body::FIRST_DTT M[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_heade r();
    int print_body_head ();
    int append_body();

    };
    #endif
    #endif

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

    #include "idr.h"

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

    int body::prepare_b ody(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_pars e(char st[])
    {
    //some functioning
    }

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

    // this is the bone of content pls look this
    void idrheader::set_ header(body b)
    {
    TOTAL_RECS=b.to tal_records; // The number of records counted.
    Found in total_records from above.
    strcpy(FIRST_DT TM,b.FIRST_DTTM ); // The least call time has been
    caught earlier. Normally first record.
    strcpy(LAST_DTT M,b.LAST_DTTM); // The biggest call time till
    now. Normally the lat record.
    strcpy(ORIG_FIL E_NAME,orig_fil e_name); // The input file name
    SWI_ID="1"; // Switch ID not know. Keeping it 1. Ask
    Damien/Antony
    REJECTED_RECS=b .rejected_recor ds; // 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::writ e_idr_header()
    {
    //some functioning
    }

    int idrheader::prin t_body_head()
    {

    //some functioning

    }

    int idrheader::appe nd_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::wri te_idr_header() '
    referenced from C:\BC5\BIN\DHAR MESH\BPL\TEST\B PL.OBJ

    Pls Help i am confused ??
  • Nicolai Hansen

    #2
    Re: Confusion over header files

    > i have a multifile program namely[color=blue]
    >
    > 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)
    >[/color]

    *snip code*
    [color=blue]
    > 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::wri te_idr_header() '
    > referenced from C:\BC5\BIN\DHAR MESH\BPL\TEST\B PL.OBJ
    >
    > Pls Help i am confused ??[/color]

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

    /Nic

    Comment

    • dharmesh Gupta

      #3
      Re: Confusion over header files

      nic@aub.dk (Nicolai Hansen) wrote in message news:<d96764ff. 0308110533.bb04 dc0@posting.goo gle.com>...[color=blue][color=green]
      > > 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)
      > >[/color]
      >
      > *snip code*
      >[color=green]
      > > 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::wri te_idr_header() '
      > > referenced from C:\BC5\BIN\DHAR MESH\BPL\TEST\B PL.OBJ
      > >
      > > Pls Help i am confused ??[/color]
      >
      > Stupid question: is the idr.cpp file added to your makefile/projectfile?
      >
      > /Nic[/color]

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

      Thanks,
      Dharmesh

      Comment

      • dharmesh Gupta

        #4
        Re: Confusion over header files

        "John Harrison" <john_andronicu s@hotmail.com> wrote in message news:<bh80qs$un dt6$1@ID-196037.news.uni-berlin.de>...[color=blue]
        > "dharmesh Gupta" <dharmesh.gupta @esteltelecom.c om> wrote in message
        > news:457ed71a.0 308110253.49372 d2a@posting.goo gle.com...[color=green]
        > > i have a multifile program namely
        > >[/color]
        >
        > [snip]
        >[color=green]
        > > 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::wri te_idr_header() '
        > > referenced from C:\BC5\BIN\DHAR MESH\BPL\TEST\B PL.OBJ
        > >
        > > Pls Help i am confused ??[/color]
        >
        > 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.
        >[/color]
        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
        [color=blue]
        > 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_rec ords; //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[/color]

        Comment

        • Noah Roberts

          #5
          Re: Confusion over header files

          [color=blue]
          > Thanks for ur reply but i am new to g++ pls help how should i add
          > idr.cpp in my makefile ??[/color]

          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


          NR

          Comment

          • dharmesh Gupta

            #6
            Re: Confusion over header files

            dharmesh.gupta@ esteltelecom.co m (dharmesh Gupta) wrote in message news:<457ed71a. 0308122224.e5ba 71a@posting.goo gle.com>...[color=blue]
            > nic@aub.dk (Nicolai Hansen) wrote in message news:<d96764ff. 0308110533.bb04 dc0@posting.goo gle.com>...[color=green][color=darkred]
            > > > 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)
            > > >[/color]
            > >
            > > *snip code*
            > >[color=darkred]
            > > > 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::wri te_idr_header() '
            > > > referenced from C:\BC5\BIN\DHAR MESH\BPL\TEST\B PL.OBJ
            > > >
            > > > Pls Help i am confused ??[/color]
            > >
            > > Stupid question: is the idr.cpp file added to your makefile/projectfile?
            > >[/color][/color]
            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 ??
            [color=blue][color=green]
            > > /Nic
            > > Thanks,[/color]
            > Dharmesh[/color]

            Comment

            Working...