I am a C++ beginner

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maabar
    New Member
    • Aug 2006
    • 6

    I am a C++ beginner

    Hi,
    Can you please help with this..
    I need to develop a program that involves two classes: FileHandling and DataProcessing.
    I have developed header files and implementation for both classes i.e. *.h and *.cpp
    Now, in my main program I have created an object of each class and I want to use these objects to access the functions of these classes.

    so my codes look something like this:

    #includ "FileHandling.h "
    #include "DataProcessing .h"

    int main()
    {
    FileHandling file;
    DataProcessing dp;

    file.readfile() ;

    return 0;
    }

    However, when I try to compile the main program, it gives me the following error about the called functions

    " In function 'main': undefined reference to 'FileHandling:: readfile()' collect2: ld returned 1 exit status"

    I have all the files in one directory and I am working on Unix.
    I use the following command to compile the program, where path is the location of the directory,:

    g++ -Wall -Lpath -o Main Main.cpp

    can you please help with? I have no clue what does this error mean

    Thanks
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    I think it might be useful to see the contents of FileHandling.h and FileHandling.cp p if they are not too long.

    Comment

    • maabar
      New Member
      • Aug 2006
      • 6

      #3
      Ok, here are the files:

      MyHeader.h:

      #ifndef _HEADERF_H
      #define _HEADERF_H


      #include <iostream>
      #include <string>

      using namespace std;

      class MyClass

      {

      public:

      void SomeFunction();

      int SomeNumber;

      };

      #endif

      The "MyClass.cp p" file which provides the body for the classheader:

      #include "classheade r.h"
      #include <iostream>
      #include <string>

      using namespace std;

      class MyClass

      {

      public:

      // One public member function

      void SomeFunction();

      // One public member variable

      int SomeNumber;

      };



      // Definition of the function

      void MyClass::SomeFu nction()

      {

      // Output the number

      cout << "SomeNumber is :"<<someNumber< <endl;

      }

      The main class "OClass.cpp ":

      // Including the header file we created

      #include "classheade r.h"

      #include <iostream>
      #include <string>

      using namespace std;

      void SomeFunction();

      int main()

      {

      // Create a new instance of MyClass named mc

      MyClass mc;

      // Set the public variable of MyClass

      mc.SomeNumber = 13;

      // Call the public function of MyClass

      mc.SomeFunction ();

      return 0;

      }

      When I compile the OClass.cpp file, I get the error that:
      In function 'main': undefined reference to 'FileHandling:: readfile()' collect2: ld returned 1 exit status"

      Can you please help?

      Thanks

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Those are not the files as none of them contain the class FileHandling

        Comment

        Working...