English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have a Header file, a implementation file with all the functions, and a main file. when I compile the implementation file, its fine. But when I compile the main file, it says ONE of my functions undeclared (first use of this function).

It doesn't happen for any of my other functions...why this one? Heres the situation:

Lets say my header file has a Class Poo, that has all its own functions. as a public member function we have
void read (Poo [], int);

Then in the implementation file we have:
void Poo::read(Poo array[],int size)
{
//code
}

Then in the main file, it includes "Poo.h"
and it calls the function by saying
Poo array[num];
read(array, num);
why is it saying 'read' undeclared (first use this function)?

2007-08-06 18:36:04 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

even after i wrote void Poo::read(Poo[],int);
it still gave me that read was undeclared

2007-08-06 18:51:29 · update #1

4 answers

If this is C++ it is not the header file that is the problem. Either the function needs to be static, or you need to declare an object of type Poo and then call Poo.read(...). Also be sure to include your header in your main file.

2007-08-06 18:50:52 · answer #1 · answered by math_prof 5 · 1 0

Hi,

You told that you defined read method as a member of Poo class. OK! If so when you want to call the read method you should be created an instance of Poo class, like this sample:

Poo array[num];
array.read(array, num);

Or if you want to not to use an instance of Poo class each time you call the read method, try to define this method (read) as static, like this in header:

static void read (Poo [], int);

and this in the implementaion part:

static void Poo::read(Poo array[],int size)
{
//code
}


And at last I recomend you if this method should be static-like, if you don't need it to access the private and protected members of calling Poo class, define this function out of the Poo class with this statements instead of yours and then you can use your currently codes to get worked:

void read (Poo [], int);

and this in the implementaion part:

static void read(Poo array[],int size)
{
//code
}

Be Succeed,
Babax.

2007-08-07 02:37:25 · answer #2 · answered by Babax 3 · 0 0

actually the way you are calling the read function is incorrect.
main can't recognize your read function to be the member of class Poo.

you should call it in your case as:

array[i].read(array,num);

but at all it wont work since i can;t assure working of your program's logic.

2007-08-07 03:13:24 · answer #3 · answered by i_am_the_next_best_one 5 · 0 0

because you have your function prototype defined as
void read (Poo [], int ) ;
that is incorrect as it is really:
void Poo::read( Poo[], int ) ;

2007-08-07 01:42:04 · answer #4 · answered by mdigitale 7 · 0 0

fedest.com, questions and answers