0

I am currently trying to access the vector defined as such:

#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>

using namespace std;
template<class T>
class file
{
    public:
        typedef vector<vector<T> > buffer;
};


int main()
{
    file<double> test;
    cout << test.buffer.size() << endl;


    std::vector<pair<string, file<double> > > list_of_files;

    for (const auto& [name, file] : list_of_files)
    {
        cout << file.buffer.size() << endl;
    }

}

the error message I am getting is that scoping the buffer like I am currently doing is invalid?, but why is it invalid? I don't see a reason why it should be?

I am in the for loop trying to iterate between the inner and outer vector of the buffer, but since I can't scope it, I am not able to access? How do i access it?

Lamda
  • 914
  • 3
  • 13
  • 39
  • 1
    `buffer` is not a vector. It is a typedef, which means that you can later declare a vector with `buffer myBuffer;` as shorthand for `vector> myBuffer;`. But your class doesn't have a vector yet. – Raymond Chen Nov 18 '17 at 21:58

1 Answers1

1

The reason for the error is because the code declares buffer as a new type for vector<vector<T>>. If you want buffer to be a member of file, you can do so like this:

template<class T>
class file
{
public:
    std::vector<std::vector<T>> buffer;
};

After changing that, main() should compile without errors.

Andy
  • 30,088
  • 6
  • 78
  • 89