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 3896
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)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Henrik S. Hansen |
last post by:
I'm new to C++, and cannot figure out why this won't compile:
std::map<std::string, int> tst;
tst = 1;
int main() { /*...*/ }
It gives me:
error: ISO C++ forbids declaration of `tst' with...
|
by: j0mbolar |
last post by:
operator = (const char *string) {
if(m_string) {
free(m_string);
m_string = 0;
}
if(string) {
m_string = strdup(string);
}
}
|
by: danny van elsen |
last post by:
hello all,
I have recently changed from gcc 3.3.1 to version 3.4.3.
In the following code
class MyClass
{
...
private:
|
by: Juhan Voolaid |
last post by:
Hi
I need help here. When i compile my program, i get this error:
$ make
g++ -c -Wall inf2_functions.cpp -o inf2_functions.o
inf2_classes.h:6: error: ISO C++ forbids declaration of ‘vector’...
|
by: gamehack |
last post by:
Hi all,
Here's the error which I'm getting when trying to compile some code:
boxmanager.h:16: error: ISO C++ forbids declaration of 'vector'
with no type
boxmanager.h:16: error: expected...
|
by: xeee |
last post by:
Hi,
I can't compile this line of code with gcc.
#define PUT_BYTE(p, v) *((unsigned char *)p)++ = (unsigned char )v
PUTBYTE(o, 0x58);
It gives me the error: ISO C++ forbids cast to...
|
by: Florian Haag |
last post by:
Hello,
I'm trying to compile a programme which compiles fine under Linux; I'm
trying it with MinGW G++ 3.4.2:
Component.h:
#ifndef COMPONENT_H_
#define COMPONENT_H_
|
by: aneuryzma |
last post by:
Hello,
I'm merging an OpenCV app with an Ogre3d app. I'm on a mac, I'm using
xCode.
When I add #include "openCVApp.h"
I got the following error:
|
by: samsneelam |
last post by:
Hi..
This is samuel, while doing a program, i encountered this problem.. Let me give you clarity regarding my prob..
I am having two files .. one is mpcplib.h it contains the follwing...
|
by: tvnaidu |
last post by:
I am using Three pthread functions below, I got ISO error, then I declared int variable called val123, then I assigned, but still I am getting error, any idea?. also I included pthread.h. compiling...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |