类内需要的类型,在哪里定义

时间:2019-03-18 03:56:25

标签: c++ class vector

问题

有一个class Samples。在该类中的是DataSample Sample。我收到“错误。没有命名类型。”

DataSample Sample;应该是DataSample [Sample];还是DataSample {Sample};,还是需要移动它?

对我来说,DataSample Sample;似乎在自身内部创建了一个循环。

DataSample似乎没有定义,对吗?

代码

#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <fstream>
#include <ctime>
#include <cstdio>
#include <cctype>

#define neuronlevel   //neuron level decomposition is used
#define sigmoid //tanh, sigmoid for output layer
#define rosen          // choose the function:
#define EPSILON 1e-30
#define MAXFUN 50000000  //upper bound for number of function evaluations
#define MINIMIZE 1      //set 1 to minimize and -1 to maximize
#define LIMIT 1e-20     //accuracy of best solution fitness desired
#define KIDS 2          //pool size of kids to be formed (use 2,3 or 4)
#define M 1             //M+2 is the number of parents participating in xover (use 1)
#define family 2        //number of parents to be replaced by good individuals(use 1 or 2)
#define sigma_zeta 0.1
#define sigma_eta 0.1   //variances used in PCX (best if fixed at these values)
#define NoSpeciesCons 300
#define NPSize KIDS + 2   //new pop size
#define RandParent M+2     //number of parents participating in PCX
#define MAXRUN 10      //number of runs each with different random initial population

time_t TicTime;
time_t TocTime;
using namespace ::std;

typedef vector<double> Layer;
typedef vector<double> Nodes;
typedef vector<double> Frame;
typedef vector<int> Sizes;
typedef vector<vector<double> > Weight;
typedef vector<vector<double> > Data;

//Mackey Glass Data is used
const int trainsize = 299; //255
const int testsize = 99; //16000
const char* trainfile = "train_embed.txt"; // may need to update this path to your own pc
const char* testfile = "test_embed.txt"; //   may need to update this path to your own pc
const char* learnt = "Learnt.txt"; //   may need to update this path to your own pc
const double MAEscalingfactor = 10;

int maxgen = 1000; //max Func eval (training time)
const int PopSize = 200;
const double MinimumError = 0.00001;
const int LayersNumber = 3; //total number of layers.
const int MaxVirtLayerSize = 20; //max number of unfold by RNN
const double MaxErrorTollerance = 0.20;
const double MomentumRate = 0;
const double Beta = 0;
double weightdecay = 0.005;

int row;
int col;
int layer;
int r;
int x;
int y;
double d_not[PopSize];
double seed, basic_seed;
int RUN;

class Samples {

public:
    Data InputValues;
    Data DataSet;
    Layer OutputValues;
    int PhoneSize;
    const char* FileName;
    int sampleSize;
    int columnSize;
    int outputSize;
    int rowSize;
    DataSample Sample;

public:
    Samples() {
    }
};

typedef vector<Samples> DataSample;

class TrainingExamples {

public:
    const char* FileName;
    int sampleSize;
    int columnSize;
    int outputSize;
    int rowSize;
    DataSample Sample;
public:
    TrainingExamples() {

1 个答案:

答案 0 :(得分:0)

错误是因为使用了不完整的类型,如果要在向量中使用Simple类型,请使用Simple的指针,并按如下所示进行正向声明...

class Samples;
typedef vector<Samples*> DataSample;
class Samples {

public:
    Data InputValues;
    Data DataSet;
    Layer OutputValues;
    int PhoneSize;
    const char* FileName;
    int sampleSize;
    int columnSize;
    int outputSize;
    int rowSize;
    DataSample Sample;

public:
    Samples() {
    }
};