2 D Vectors(Vector of Vectors) giving problem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class input_for_matrix {
	private:
		. . .
	public: 
		 vector <vector <double> > input ;
                int lenFinder (char *arg1)
                {
                 ....//input is not used here
                }
          vector< vector<double> > *putinArray (char *arg1, int size)  /*This method puts numbers read from file into the array*/
           {
                input.resize(size);
		for (int i=0 ; i < size ; i++) input[i].resize(size + 1) ;
                if (myfile.is_open())  
		  {
		    while ( myfile.good() )
		    {
		      for (int i=0 ; i<size  ; i++)
		   	{
			 for (int j=0 ; j<=size  ; j++)
 			{
			      getline (myfile,line);
			       if ( isdigit(line[1]) ) 
				{ 
				 input[i][j] = atof(line.c_str());
		 cout << "input["<<i<<"]["<<j<<"]=" << input[i][j] << "\t";
				}
			}//inner for ends
			cout << endl ;
			}//outer for ends
			break;
		    }//while ends
	    myfile.close();
	    return &input;
	}//if ends
      }//putinArray ends here
};//class ends here

//This is in some other file with different inherited class
class Guass_El : public input_for_matrix {...};
int main(..)
{
	vector <vector <double> > *fn ;
    fn=obj1->putinArray(argv[1],size1);	//now fn is pointer to vector of vectors
cout << "The (2,3)nd element is  " << *(fn [1][2] ) << endl;/*This is what giving me error, I exactly don't know, but this is how elements should be accessed*/
}

error: no match foroperator*’ in ‘*(fn + 12u)->std::vector<_Tp, _Alloc>::operator[] [with _Tp = std::vector<double>, _Alloc = std::allocator<std::vector<double> >, std::vector<_Tp, _Alloc>::reference = std::vector<double>&, std::vector<_Tp, _Alloc>::size_type = unsigned int](2u)’


So could you please help me..? I am tired of thinking what is going wrong. Of course, I donot want to use 'fn' to access only 1 element. I will put it in the for loop to manipulate it, but for loop will only have indices i and j and this is what statement will eventually be.

So please please help me to access the elements of this vector of vectors.

Thanks in advance
Sagar
Hi

What is the type of fn ? where does obj1 come from ?
why do you define fn as a pointer to a vector, make it a normal one, without pointer
and how to you set your, fn, vector to a temporary reference( I dont see obj1 in your main, nor in gloabl scope)? is &input out of it's scope alive ?
is it not destroyed ?
your program should work if putinArray returns a vector< vector<double> >, and not a reference, and if fn is not a pointer


hope it helps
Last edited on
Topic archived. No new replies allowed.