473,378 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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 3925
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.