I am working on genetically evolved neural networks. I wrote a program using visual studio 2005 in 2008. Now I converted the program into Eclipse(Linux) and VS 2013(Win) projects with c++11 support. After running, both projects gave same error:
taking address of temporary [-fpermissive]
After searching a lot I found this error arises as new C++ standards doesn't allow to take address of a temporary object. As all objects are created using "new" (so I guess they should remain available all the time). I figured out the problem partially but don't know how to solve it. If you run the eclipse project it will highlight just two errors in the project.
As its hard to explain in words as it need full code to examine so I have hosted eclipse project on git at https://bitbucket.org/a-akram/geans.git which I made accessible to everyone.
Main problem is with variables wp1
& wp2
. m_vPopulatin
is a vector containing addresses of neural networks.
CNeuralNetwork* CGeneticEngine::Evolve()
{
CLearningEngine *l;
double totalError = 0.0;
for (int iter = 0;iter < CGN_MAXITER; iter++)
{
for (int i = 0;i < CGN_POPULATION; i++)
{
l = new CLearningEngine(m_vPopulation[i]);
l->Run(m_vTrainingDataset);
for(unsigned int p = 0; p < m_vTrainingDataset->size(); p++)
{
totalError = totalError + m_vPopulation[i]->getm_dTotalNetworkError();
totalError = totalError/m_vTrainingDataset->size();
}
if (totalError < CGN_THRESHOLD)
return m_vPopulation[i];
m_dErrors[i] = totalError;
}
SortFitnesses();
NewPopulation();
}
return NULL;
}
void CGeneticEngine::NewPopulation()
{
int id1, id2;
double temp;
std::vector <CSynapticConnection *> *wp1;
std::vector <CSynapticConnection *> *wp2;
for (int i=0;i<CGN_POPULATION / 2;i++)
{
id1 = rand() % CGN_POPULATION / 2;
id2 = rand() % CGN_POPULATION / 2 + CGN_POPULATION / 2;
wp1 = &m_vPopulation[id1]->getm_vListofSynaptics();
wp2 = &m_vPopulation[id2]->getm_vListofSynaptics();
// Cross over the weights.
for (int j = 0; j < 2; j++)
{
temp = (*wp1)[j+6]->getWeight();
(*wp1)[j+6]->setWeight((*wp2)[j+6]->getWeight() );
(*wp2)[j+6]->setWeight(temp);
}
// adding slight genetic change due to crossover randomly.
if (rand() % 10 < 2)
{
for(unsigned int j = 0; j < wp1->size();j++)
(*wp1)[j]->changeWeight((double)(rand())/(32767/2) - 1);
for(unsigned int j = 0; j < wp2->size();j++)
(*wp2)[j]->changeWeight((double)(rand())/(32767/2) - 1);
}
}
}
As this is my first question on this forum so I might not phrased well so I request moderators not to close it at the moment. I will make it more clear if necessary. But with the project files in hand it will be very easy for you guys to figure out the problem and solution.
I will highly appreciate your help to resolve the issue... please let me know if you need any further information.