Team Leader
25Apr2007,08:26   #11
DaWei's Avatar
You can not assign function addresses like this:
Code:
    void (*functionptr[3])(int *) = {void update(int *), void deleted(int *), void display(int *)};
"void update (int *)" looks like a declaration, not an address.
"update (int *)" looks like a messed up invocation, not an address.
Use the following form:
Code:
    void (*functionptr[3])(int) = {update, deleted, display};
You should not be using VC++6.0 unless there is an absolutely compelling reason to do so (your tutor has threatened to shoot you, or something). VC++6.0 was written BEFORE the C++ standard was adopted. It is non-compliant in many respects. If you use it, you will have to disregard many of the things that you have been told about producing robust and compliant code.

VC++2005 Express Edition is free for the download. If you want a CD, you only have to pay shipping. Another free compiler is Dev-Cpp, from Bloodshed. It uses MinGW, a gcc/g++ port to Windows. Neither is fully compliant with the standard (few compilers are), but they are much, much better than VC++6.0.
Contributor
25Apr2007,13:43   #12
Peter_APIIT's Avatar
From my knowledge, one can assign name of array name to a pointer such as
Code:
int *ptr;
int array[3];
ptr = array;            // or ptr = &array; -- Array name is constant pointer;

The same concept applied to function pointer. 
Name of function is constant pointer to that function. 
The correct methods is 
void (*functionptr[3])(int *) = {update, deleted, display};
and not
void (*functionptr[3](int *) = {update(), deleted(), dispaly()};
I just guess. I don't know whether it is correct.

By the way, i do not understand this two different code.
Code:
int *ptr;
int number = 1;
ptr = &number;
and

Code:
int number = 2;
int *ptr = number;
* and -> is deference operator - to get the value
& is to get the address.

Sorry for my stupidness.

Thanks for your help.
I will post this program afterwards in order to help someone to understand function pointer, array of structure pointer and file operation.

Your help is greatly appreciated by me and others.
Go4Expert Founder
25Apr2007,15:05   #13
shabbir's Avatar
Code:
int *ptr; // Declaring a pointer which may point to any undefined location
int number = 1; // Declaring a variable and assigning the value 1 to it
ptr = &number; // Assigning the address of the variable number to the pointer ptr
See my comments after each line.

Code:
int number = 2; // Declaring a variable and assigning the value 1 to it
int *ptr = number; // This should be int *ptr = &number; which will have the same effect as above 3rd ststement
See my comments after each line.

Now I would suggest you create seperate thread for each of your query and having the same query in the same thread has 2 disadvantage.

1. some queries may get unnoticed.
2. Other people searching will not be helped and so may ask the same question over and over again.
Team Leader
25Apr2007,16:32   #14
DaWei's Avatar
One can assign an array name to a pointer (myPtr = myArray) simply because the standard says that the compiler must accept that and make the conversion. It is equivalent to "myPtr = &myArray [0]". Note that this yields some apparent equivalencies in usage, however myPtr and myArray are NOT the same. When the two are dereferenced (myPtr [3] and myArray [3]), different machine code is emitted in order to produce the value in element 3. See the tutorial in my signature, the section WHAT IS NOT A POINTER, for more.
Quote:
4.2 Array-to-pointer conversion [conv.array]

1 An lvalue of type "array of N T" or "array of unknown bound of T" can
be converted to an rvalue of type "pointer to T." The result is a
pointer to the first element of the array.

2 A string literal (_lex.string_) that is not a wide string literal can
be converted to an rvalue of type "pointer to char"; a wide string
literal can be converted to an rvalue of type "pointer to wchar_t".
In either case, the result is a pointer to the first element of the
array. [Note: this conversion is deprecated. See Annex _depr_. ]
For the purpose of ranking in overload resolution (_over.ics.scs_),
....
Contributor
27Apr2007,10:41   #15
Peter_APIIT's Avatar
Thanks for your help.