HiddenLayer::HiddenLayer(int numHidden, int numInput, float thresh, bool init)
{ hiddenNodes = new HiddenNeuron[numHidden](numInput, thresh, init);
numNeurons = numHidden;
};
Error:
ISO C++ forbids initialization in array new
how do i write this so i wont get an error?
id love to see your answer as a source code/
thanks in advance
7 3760
It looks like you're trying to both initialize an array and/or call a constructor in the same statement. Pick one. If it's a template argument, use <> instead of [].
its not a template argument
in java i did:
public HiddenLayer(int numHidden, int numInput, double thresh, boolean init)
{
hiddenNodes = new HiddenNeuron[numHidden];
for(int i=0; i<numHidden; i++)
hiddenNodes[i] = new HiddenNeuron(numInput, thresh, init);
numNeurons = numHidden;
}
and it compiles well... however i cant do the same thing in c++
That Java code looks like it would translate perfectly to C++, with changes for C++'s class syntax. I don't see where the error would come from, assuming hiddenNodes is a member variable of the class.
That Java code looks like it would translate perfectly to C++, with changes for C++'s class syntax. I don't see where the error would come from, assuming hiddenNodes is a member variable of the class.
thank you for the reply, heres a post of the entire code, i cant seem to get it to compile...
the error code is shown below,
im using Bloodshed Dev c++ ver 4.9.9.2 -
#include <vector>
-
#include <math.h>
-
#include <iostream>
-
#include <stdlib.h>
-
using namespace std;
-
-
class Neuron {
-
-
public:
-
Neuron();
-
Neuron(int axons, float threshVal, bool INIT);
-
Neuron(const Neuron& parent);
-
~Neuron();
-
-
// input unit functions
-
void setNumInputs(int val);
-
void setInputSet(float *inputs, int numInSet);
-
-
// output signal functions
-
float generateOutputSignal(int activationFunction);
-
float calculateOutputSignalDerivative(int afun);
-
-
// learning functions
-
void calculateWeightBiasCorrection(float learningRate);
-
-
// set weight set values
-
void generateRandomInputWeights();
-
void setInputWeightSet(float *weights, int setSize);
-
void mutateInputWeights(float factor);
-
void updateWeightsBiases();
-
void increaseInputWeights(float factor);
-
void decreaseInputWeights(float factor);
-
-
// bias functions
-
void setBias(float TVal);
-
void mutateBias(float factor);
-
-
// print functions
-
void printWeightSet();
-
-
int id;
-
-
// input set variables/vectors
-
float *neuronInputSet;
-
int numInputs;
-
float *inputWeightSet;
-
-
// threshold for firing
-
float bias;
-
-
// output signal value
-
float outputSignal;
-
-
// error correction / learning
-
// used to calculate error term
-
float errorInformation;
-
float *weightCorrection;
-
float biasCorrection;
-
float sumWeightedInput;
-
-
// static counter
-
static int idCounter;
-
};
-
class HiddenNeuron : public Neuron
-
{
-
public:
-
HiddenNeuron(int, float, bool);
-
void calculateHiddenError(int afun);
-
};
-
//-----------------------------------
-
class HiddenLayer
-
{
-
public:
-
HiddenNeuron *hiddenNodes;
-
int numNeurons;
-
HiddenLayer(int, int, float, bool);
-
~HiddenLayer();
-
};
-
//-----------------------------------
-
HiddenLayer::HiddenLayer(int numHidden, int numInput, float thresh, bool init)
-
{
-
//hiddenNodes = new HiddenNeuron[numHidden](numInput, thresh, init);
-
hiddenNodes = new HiddenNeuron[numHidden];
-
for(int i=0; i<numHidden; i++)
-
{hiddenNodes[i] = new HiddenNeuron(numInput, thresh, init);}
-
numNeurons = numHidden;
-
};
-
-
HiddenLayer::~HiddenLayer()
-
{
-
delete [] hiddenNodes;
-
}
-
\c++\hiddenLayer.cpp In constructor `HiddenLayer::HiddenLayer(int, int, float, bool)':
83 \c++\hiddenLayer.cpp no matching function for call to `HiddenNeuron::HiddenNeuron()'
note \c++\hiddenLayer.cpp:65 candidates are: HiddenNeuron::HiddenNeuron(const HiddenNeuron&)
note \c++\hiddenLayer.cpp:65
HiddenNeuron::HiddenNeuron(int, float, bool)
85 \c++\hiddenLayer.cpp no match for 'operator=' in '*(((HiddenLayer*)this)->HiddenLayer::hiddenNodes + (+(((unsigned int)i) * 40u))) = (((HiddenNeuron*)operator new(40u)), (<anonymous>->HiddenNeuron::HiddenNeuron(numInput, thresh, (+init)), <anonymous>))'
note \c++\hiddenLayer.cpp:65 candidates are: HiddenNeuron& HiddenNeuron::operator=(const HiddenNeuron&)
C:\Documents and Settings\aresh\Desktop\Makefile.win [Build Error] [thesis/c++/hiddenLayer.o] Error 1 -
#include <vector>
-
#include <math.h>
-
#include <iostream>
-
#include <stdlib.h>
-
using namespace std;
-
-
class Neuron {
-
-
public:
-
Neuron();
-
Neuron(int axons, float threshVal, bool INIT);
-
Neuron(const Neuron& parent);
-
~Neuron();
-
-
// input unit functions
-
void setNumInputs(int val);
-
void setInputSet(float *inputs, int numInSet);
-
-
// output signal functions
-
float generateOutputSignal(int activationFunction);
-
float calculateOutputSignalDerivative(int afun);
-
-
// learning functions
-
void calculateWeightBiasCorrection(float learningRate);
-
-
// set weight set values
-
void generateRandomInputWeights();
-
void setInputWeightSet(float *weights, int setSize);
-
void mutateInputWeights(float factor);
-
void updateWeightsBiases();
-
void increaseInputWeights(float factor);
-
void decreaseInputWeights(float factor);
-
-
// bias functions
-
void setBias(float TVal);
-
void mutateBias(float factor);
-
-
// print functions
-
void printWeightSet();
-
-
int id;
-
-
// input set variables/vectors
-
float *neuronInputSet;
-
int numInputs;
-
float *inputWeightSet;
-
-
// threshold for firing
-
float bias;
-
-
// output signal value
-
float outputSignal;
-
-
// error correction / learning
-
// used to calculate error term
-
float errorInformation;
-
float *weightCorrection;
-
float biasCorrection;
-
float sumWeightedInput;
-
-
// static counter
-
static int idCounter;
-
};
-
class HiddenNeuron : public Neuron
-
{
-
public:
-
HiddenNeuron(int, float, bool);
-
void calculateHiddenError(int afun);
-
};
-
//------------------------------------
-
HiddenNeuron::HiddenNeuron(int numInputs, float threshold, bool init):Neuron(numInputs, threshold, init)
-
{ }
-
-
void HiddenNeuron::calculateHiddenError(int afun)
-
{
-
float outputSignalDerivative = calculateOutputSignalDerivative(afun);
-
errorInformation *= outputSignalDerivative;
-
}
-
-
-
You've certainly got some errors there.
Line 83:
This line is fine if you remove line 82. That's fine array declaration syntax, but line 82 is just a mess. It looks as though you tried to initialize the entire array with elements passing those parameters to the constructor, but that just doesn't work.
Line 85:
You're trying to reinitialize the array at each step. Use the array index operator, [], to access the elements and initialize them.
changed it to:
HiddenLayer::HiddenLayer(int numHidden, int numInput, float thresh, bool init)
{
hiddenNodes = new HiddenNeuron[numHidden];
for(int i=0; i<numHidden; i++)
{hiddenNodes[i] = HiddenNeuron(numInput, thresh, init);}
numNeurons = numHidden;
}; but i get the following error now!
this is what it calls so i dont know how to seperate both the array and initialization.....
HiddenNeuron::HiddenNeuron(int numInputs, float threshold, bool init):Neuron(numInputs, threshold, init)
{ }
ERRORS
\c++\hiddenLayer.cpp In constructor `HiddenLayer::HiddenLayer(int, int, float, bool)':
83 \c++\hiddenLayer.cpp no matching function for call to `HiddenNeuron::HiddenNeuron()'
note \c++\hiddenLayer.cpp:65 candidates are: HiddenNeuron::HiddenNeuron(const HiddenNeuron&)
note \c++\hiddenLayer.cpp:65 HiddenNeuron::HiddenNeuron(int, float, bool)
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
2 posts
views
Thread by Henrik S. Hansen |
last post: by
|
5 posts
views
Thread by j0mbolar |
last post: by
|
6 posts
views
Thread by danny van elsen |
last post: by
|
4 posts
views
Thread by Juhan Voolaid |
last post: by
|
3 posts
views
Thread by gamehack |
last post: by
| |
7 posts
views
Thread by Florian Haag |
last post: by
|
8 posts
views
Thread by aneuryzma |
last post: by
| | | | | | | | | | | | |