vector of struct vectors

I am making database management program for homework using the vector library and I keep getting an error when I try to use a vector of struct vectors. Is this even possible to do or am I just doing it wrong?

The program is supposed to display a table to jobs for a given day showing the customer's name, address, and the cost of the job

Here is where I defined the structs and vectors.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>
#include<vector>
#include<string>
using namespace std;

struct CustomerType {
	string name;
	string address;
	int cost;
};

struct Day {
	vector<CustomerType> customer;
};

typedef vector<Day> dayvec;
typedef vector<int> intvec;

dayvec week(7);
intvec length(7,0);


Here is where I'm getting the error
 
  display(week[dayval], length[dayval]);
no suitable user-defined conversion from "Day" to "dayvec" exists
no suitable constructor exists to convert from "int" to "std::vector<int, std::allocator<int>>


the dayval variable is an int variable corresponding to a certain day of the week. Sunday = 0, Monday = 1, etc. There isn't a problem with this so the issue must be with either the vectors or the structs.

Any help is much appreciated.
Last edited on
What is the definition of this function expecting as arguments?

display(week[dayval], length[dayval])
vector<Day> and vector<int>
Something like this, perhaps:

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
struct customer {

    std::string name;
    std::string address;
    int cost;
};

void display( const customer& cust ) {

    std::cout << "customer{ name: " << cust.name << "  address: "
              << cust.address << "  cost: " << cust.cost << " }\n" ;
}

struct day {

    std::vector<customer> customers ;
    int day_num = 1 ;
};

void display( const day& a_day ) {

    std::cout << "day #" << a_day.day_num << '\n' ;

    for( const auto& cust : a_day.customers ) {

        std::cout << '\t' ;
        display(cust) ;
    }
}

using week = std::vector<day> ;
typedef std::vector<day> week ; // same as above

void display( const week& wk ) {

    for( const auto& a_day : wk ) display(a_day) ;
}
vector<Day> and vector<int>


The function is expecting vectors, but here it is being sent an individual element of each vector, or a Day and an int. The compiler message is saying it can't do that conversion.

display(week[dayval], length[dayval])


Oh. That makes sense. Thank you!
Topic archived. No new replies allowed.