Advertisement

10.11.2005 at 10:38PM PDT, ID: 21591967
[x]
Attachment Details

vector of vector to double pointers?

Asked by slyong in C++ Programming Language, Microsoft Visual C++

Tags: vector, double

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
[+][-]10.12.2005 at 01:54AM PDT, ID: 15067125

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.12.2005 at 02:11AM PDT, ID: 15067190

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.12.2005 at 02:36AM PDT, ID: 15067283

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.12.2005 at 02:48AM PDT, ID: 15067321

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.12.2005 at 02:59AM PDT, ID: 15067355

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.12.2005 at 03:15AM PDT, ID: 15067417

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.12.2005 at 04:02AM PDT, ID: 15067607

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C++ Programming Language, Microsoft Visual C++
Tags: vector, double
Sign Up Now!
Solution Provided By: itsmeandnobodyelse
Participating Experts: 2
Solution Grade: A
 
 
[+][-]10.12.2005 at 04:03AM PDT, ID: 15067610

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10.12.2005 at 04:19AM PDT, ID: 15067689

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.12.2005 at 04:23AM PDT, ID: 15067707

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.12.2005 at 04:34AM PDT, ID: 15067765

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.15.2005 at 09:58AM PDT, ID: 15091796

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32