delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/18/21:33:27

Message-ID: <147BBF8976F0D211888508002BA60B66015A663B@mail8.ntu.edu.sg>
From: #CHUA CHAI GUAN# <PH877172 AT ntu DOT edu DOT sg>
To: "'djgpp AT delorie DOT com'" <djgpp AT delorie DOT com>
Subject: pointer problem
Date: Wed, 19 May 1999 09:33:03 +0800
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2232.9)
Reply-To: djgpp AT delorie DOT com

To whom it may concern,

a) What's the syntax in JDGPP compiler to call a function to a pointer ?

C:\CCG\gann\gann>make -k
gcc -O6 -Wall -fstrict-prototypes -funroll-loops -finline-functions  -c
NN.cpp
NN.cpp: In method `void NN::trainBP(int, float **, int *, int = 1, int = 1,
enum
 trainAlgs = STD_GRAD_DESC)':
NN.cpp:534: must use .* or ->* to call pointer-to-member function in `fp
(...)'
NN.cpp:540: must use .* or ->* to call pointer-to-member function in `fp
(...)'
make.exe: *** [NN.o] Error 1
make.exe: Target `all' not remade because of errors.


I tried to fix it by adding the .* in front of fp. It gave the following
problem :- 

C:\CCG\gann\gann>make -k
gcc -O6 -Wall -fstrict-prototypes -funroll-loops -finline-functions  -c
NN.cpp
NN.cpp: In method `void NN::trainBP(int, float **, int *, int = 1, int = 1,
enum
 trainAlgs = STD_GRAD_DESC)':
NN.cpp:534: parse error before `.*'
NN.cpp:540: parse error before `.*'
make.exe: *** [NN.o] Error 1
make.exe: Target `all' not remade because of errors.

What's ur advices ?

Attached herewith the part of the program

//void NN::trainBP(int patCount, float **patterns, int *targets, int
iterations=1, int shuffle=1, void *trainFct(float *input, int target)) {
void NN::trainBP(int patCount, float **patterns, int *targets, int
iterations=1, int shuffle=1, trainAlgs trainAlg = STD_GRAD_DESC) {

    // Find the apropriate function pointer to the training algorithm
function.
    void (NN::*fp)(float *, int);
    switch (trainAlg) {
    case STD_GRAD_DESC:
	fp = &bp;
	break;
    case PSEUDO_NEWTON:
	fp = &pnaBP;
	break;
    default:
	fprintf(stderr, "NN::trainBP: Error (Unknown training
algorithm)\n");
	fflush(stderr);
	exit(1);
    }


    for (int it=0; it<iterations; it++) {
	if (shuffle) {

	    // Create and initialize the order array  [time: O(patCount)]
	    int order[patCount];
	    for (int i=0; i<patCount; i++) {
		order[i]=i;
	    }

	    // Permutate (shuffle) the contents of the `order' array  [time:
O(patCount)]
	    // For each index i...
	    for (int i=0; i<patCount; i++) {
		// ...pick at random an index j and switch the content of
order[i] and order[j].
		int j = rand() % patCount;
		int tmp = order[i];
		order[i] = order[j];
		order[j] = tmp;
	    }

	    // Train with each pattern in the order found
	    for (int mu=0; mu<patCount; mu++) {
               fp(patterns[order[mu]], targets[order[mu]]);
	    }
	    
	} else {
	    // Train with each pattern in the order they are given
	    for (int mu=0; mu<patCount; mu++) {
                fp(patterns[mu], targets[mu]);
	    }
	}
    }
Thanks
ccg


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019