472,780 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 software developers and data experts.

ISO C++ forbids

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
Dec 11 '07 #1
7 3896
Laharl
849 Expert 512MB
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 [].
Dec 11 '07 #2
its not a template argument
Dec 11 '07 #3
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++
Dec 11 '07 #4
Laharl
849 Expert 512MB
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.
Dec 11 '07 #5
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

Expand|Select|Wrap|Line Numbers
  1. #include <vector>
  2. #include <math.h>
  3. #include <iostream>
  4. #include <stdlib.h>
  5. using namespace std;
  6.  
  7. class Neuron {
  8.  
  9. public:
  10.   Neuron();
  11.   Neuron(int axons, float threshVal, bool INIT);
  12.   Neuron(const Neuron& parent);
  13.   ~Neuron();
  14.  
  15.   // input unit functions
  16.   void setNumInputs(int val);
  17.   void setInputSet(float *inputs, int numInSet);
  18.  
  19.   // output signal functions
  20.   float generateOutputSignal(int activationFunction);
  21.   float calculateOutputSignalDerivative(int afun);
  22.  
  23.   // learning functions
  24.   void calculateWeightBiasCorrection(float learningRate);
  25.  
  26.   // set weight set values
  27.   void generateRandomInputWeights();
  28.   void setInputWeightSet(float *weights, int setSize);
  29.   void mutateInputWeights(float factor);
  30.   void updateWeightsBiases();
  31.   void increaseInputWeights(float factor);
  32.   void decreaseInputWeights(float factor);
  33.  
  34.   // bias functions
  35.   void setBias(float TVal);
  36.   void mutateBias(float factor);
  37.  
  38.   // print functions
  39.   void printWeightSet();
  40.  
  41.   int id;
  42.  
  43. // input set variables/vectors
  44.   float *neuronInputSet;
  45.   int numInputs;
  46.   float *inputWeightSet;
  47.  
  48. // threshold for firing
  49.   float bias;
  50.  
  51. // output signal value
  52.   float outputSignal;
  53.  
  54. // error correction / learning
  55. // used to calculate error term
  56.   float errorInformation;
  57.   float *weightCorrection;
  58.   float biasCorrection;
  59.   float sumWeightedInput;
  60.  
  61. // static counter
  62.   static int idCounter;
  63. };
  64. class HiddenNeuron : public Neuron
  65. {
  66. public:
  67.   HiddenNeuron(int, float, bool);
  68.   void calculateHiddenError(int afun);
  69. };
  70. //-----------------------------------
  71. class HiddenLayer
  72. {
  73. public:
  74.   HiddenNeuron *hiddenNodes;
  75.   int numNeurons;
  76.   HiddenLayer(int, int, float, bool);
  77.   ~HiddenLayer();
  78. };
  79. //-----------------------------------
  80. HiddenLayer::HiddenLayer(int numHidden, int numInput, float thresh, bool init)
  81.   //hiddenNodes = new HiddenNeuron[numHidden](numInput, thresh, init);
  82.     hiddenNodes = new HiddenNeuron[numHidden];
  83.     for(int i=0; i<numHidden; i++)
  84.           {hiddenNodes[i] = new HiddenNeuron(numInput, thresh, init);}
  85.   numNeurons = numHidden;
  86. };
  87.  
  88. HiddenLayer::~HiddenLayer()
  89.   delete [] hiddenNodes;
  90. }
  91.  
\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


Expand|Select|Wrap|Line Numbers
  1. #include <vector>
  2. #include <math.h>
  3. #include <iostream>
  4. #include <stdlib.h>
  5. using namespace std;
  6.  
  7. class Neuron {
  8.  
  9. public:
  10.   Neuron();
  11.   Neuron(int axons, float threshVal, bool INIT);
  12.   Neuron(const Neuron& parent);
  13.   ~Neuron();
  14.  
  15.   // input unit functions
  16.   void setNumInputs(int val);
  17.   void setInputSet(float *inputs, int numInSet);
  18.  
  19.   // output signal functions
  20.   float generateOutputSignal(int activationFunction);
  21.   float calculateOutputSignalDerivative(int afun);
  22.  
  23.   // learning functions
  24.   void calculateWeightBiasCorrection(float learningRate);
  25.  
  26.   // set weight set values
  27.   void generateRandomInputWeights();
  28.   void setInputWeightSet(float *weights, int setSize);
  29.   void mutateInputWeights(float factor);
  30.   void updateWeightsBiases();
  31.   void increaseInputWeights(float factor);
  32.   void decreaseInputWeights(float factor);
  33.  
  34.   // bias functions
  35.   void setBias(float TVal);
  36.   void mutateBias(float factor);
  37.  
  38.   // print functions
  39.   void printWeightSet();
  40.  
  41.   int id;
  42.  
  43. // input set variables/vectors
  44.   float *neuronInputSet;
  45.   int numInputs;
  46.   float *inputWeightSet;
  47.  
  48. // threshold for firing
  49.   float bias;
  50.  
  51. // output signal value
  52.   float outputSignal;
  53.  
  54. // error correction / learning
  55. // used to calculate error term
  56.   float errorInformation;
  57.   float *weightCorrection;
  58.   float biasCorrection;
  59.   float sumWeightedInput;
  60.  
  61. // static counter
  62.   static int idCounter;
  63. };
  64. class HiddenNeuron : public Neuron
  65. {
  66. public:
  67.   HiddenNeuron(int, float, bool);
  68.   void calculateHiddenError(int afun);
  69. };
  70. //------------------------------------
  71. HiddenNeuron::HiddenNeuron(int numInputs, float threshold, bool init):Neuron(numInputs, threshold, init)
  72. { }
  73.  
  74. void HiddenNeuron::calculateHiddenError(int afun)
  75. {
  76.   float outputSignalDerivative = calculateOutputSignalDerivative(afun);
  77.   errorInformation *= outputSignalDerivative;
  78. }
  79.  
  80.  
  81.  
Dec 11 '07 #6
Laharl
849 Expert 512MB
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.
Dec 11 '07 #7
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)
Dec 12 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
5
by: j0mbolar | last post by:
operator = (const char *string) { if(m_string) { free(m_string); m_string = 0; } if(string) { m_string = strdup(string); } }
6
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:
4
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’...
3
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...
0
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...
7
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_
8
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:
6
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...
10
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...
0
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...
0
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...
0
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...
0
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 ...
0
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...
5
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...
0
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=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.