468,514 Members | 1,122 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,514 developers. It's quick & easy.

I am a C++ beginner

6
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
Aug 29 '06 #1
3 1664
Banfa
9,056 Expert Mod 8TB
I think it might be useful to see the contents of FileHandling.h and FileHandling.cpp if they are not too long.
Aug 29 '06 #2
maabar
6
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.cpp" file which provides the body for the classheader:

#include "classheader.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::SomeFunction()

{

// Output the number

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

}

The main class "OClass.cpp":

// Including the header file we created

#include "classheader.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
Aug 30 '06 #3
Banfa
9,056 Expert Mod 8TB
Those are not the files as none of them contain the class FileHandling
Sep 1 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Richard B. Kreckel | last post: by
8 posts views Thread by Grrrbau | last post: by
7 posts views Thread by Rensjuh | last post: by
27 posts views Thread by MHoffman | last post: by
18 posts views Thread by mitchellpal | last post: by
10 posts views Thread by Roman Zeilinger | last post: by
10 posts views Thread by hamza612 | last post: by
22 posts views Thread by ddg_linux | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.