我的代码有问题,我不太明白。
我使用«gcc 版本 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1)»
编辑:我用这一行编译
g++ -g -std=c++0x -o "GeneticEngine.o" -c "GeneticEngine.cpp"
这是我遇到的错误:
GeneticEngine.tpl:16:5: erreur: parenthesized initializer in array new [-fpermissive]
那是我的(最小化)代码:
遗传引擎.hpp
#include "GeneticThread.hpp"
template <class T>
class GeneticEngine
{
public:
template <typename ... Args>
GeneticEngine(int nb_threads,float taux_mut,int tranche_mut,std::string filename,int pop_size,Args& ... args);
/* Other code */
private:
GeneticThread<T>* islands; /* Cause of error */
int size;
};
#include "GeneticEngine.tpl"
遗传引擎.tpl
template <class T>
template <typename ... Args>
GeneticEngine<T>::GeneticEngine(int nb_threads,float taux_mut,int tranche_mut,std::string filename,int pop_size,Args& ... args) : size(nb_threads)
{
/*next line is 16 : Error */
islands = new GeneticThread<T>[size](taux_mut,tranche_mut,filename,pop_size/nb_threads,std::forward<Args>(args)...);
};
遗传线程.hpp
template <class T>
class GeneticThread
{
public:
template <typename ... Args>
GeneticThread(float taux_mut,int tranche_mut,std::string filename,int pop_size,Args& ... args)
{ /* code ... */ };
/* Other code */
};
我已经阅读了这个(使用模板时初始化数组),但它并不完全相同。
如果您有一个想法来解决它而无需:[最后我使用这个:/]
GeneticThread<T>** islands;
islands = new GeneticThread<T>*[size];
for(int i=0;i<size;++i)
islands[i] = new GeneticThread<T>(taux_mut,tranche_mut,filename,pop_size/nb_threads,std::forward<Args>(args)...);
我希望有:
GeneticThread<T>* islands;
有办法吗???
我尝试:
islands = new (GeneticThread<T>[size](taux_mut,tranche_mut,filename,pop_size/nb_threads,std::forward<Args>(args)...));
和
islands = new GeneticThread<T>(taux_mut,tranche_mut,filename,pop_size/nb_threads,std::forward<Args>(args)...)[size];
但它不起作用。
谢谢。