Hi Guys,
It is my turn to face some problem here... The followings is my C++ code and output:
#include <iostream>
#include <vector>
#include "Layer.h"
using namespace std;
int main(int argc, char *argv[])
{
vector<double> *iVec;
iVec = new vector<double>;
iVec->push_back(1.23);
iVec->push_back(2.34);
iVec->push_back(3.45);
iVec->push_back(4.56);
for (int i = 0; i < 3; ++i) {
if (i == 0) {
vector<Layer *> v_layer;
vector<double> *h_output1, *h_output2;
cout << "i == 0\n";
h_output1 = NULL;
v_layer.push_back(new Layer(5, &iVec, &h_output1, 1));
cout << (*v_layer.at(0)->iVector)-
>size() << ":" << (*v_layer.at(0)->oVector)-
>size() << "\n";
h_output2 = NULL;
v_layer.push_back(new Layer(5, &iVec, &h_output2, 1));
cout << (*v_layer.at(0)->iVector)-
>size() << ":" << (*v_layer.at(0)->oVector)-
>size() << "\n\n";
}
if (i == 1) {
vector<Layer *> v_layer;
vector<vector<double> *> h_output;
cout << "i == 1\n";
h_output.push_back(NULL);
v_layer.push_back(new Layer(5, &iVec, &h_output.back(), 1));
cout << (*v_layer.at(0)->iVector)-
>size() << ":" << (*v_layer.at(0)->oVector)-
>size() << "\n";
h_output.push_back(NULL);
v_layer.push_back(new Layer(5, &iVec, &h_output.back(), 1));
cout << (*v_layer.at(0)->iVector)-
>size() << ":" << (*v_layer.at(0)->oVector)-
>size() << "\n\n";
}
if (i == 2) {
vector<Layer *> v_layer;
vector<double> *h_output[2];
cout << "i == 2\n";
h_output[0] = NULL;
v_layer.push_back(new Layer(5, &iVec, &h_output[0], 1));
cout << (*v_layer.at(0)->iVector)-
>size() << ":" << (*v_layer.at(0)->oVector)-
>size() << "\n";
h_output[1] = NULL;
v_layer.push_back(new Layer(5, &iVec, &h_output[1], 1));
cout << (*v_layer.at(0)->iVector)-
>size() << ":" << (*v_layer.at(0)->oVector)-
>size() << "\n\n";
}
}
return EXIT_SUCCESS;
}
~.~.~.~.~.~.~.~.~.~.~.~.~.
~.~.~.~.~.
~.~.~.~.~.
~.~.~.~.~.
~.~.~.~.~.
~.~.~.~.~.
~.~.~.~.~.
~.~.~.~.~.
~.~.~.~.~.
~.~.~.
[slyong@localhost vault]$ ./a.out
i == 0
4:5
4:5
i == 1
4:5
4:0
i == 2
4:5
4:5
My problem is that when i == 0, I use variables of "pointer to a vector containing doubles", vector<double> *. When i == 1, I use a vector of "pointer to a vector containing doubles", vector<vector<double> *> and when i==3, I use an array of "pointer to a vector containing doubles". However when I use vector<vector<double> *> the result is different.
I have been scratching my head for quite a while now.. help?
Start Free Trial