vector of struct vectors

May 20, 2017 at 6:11pm
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 May 20, 2017 at 6:33pm
May 20, 2017 at 8:24pm
What is the definition of this function expecting as arguments?

display(week[dayval], length[dayval])
May 21, 2017 at 2:01am
vector<Day> and vector<int>
May 21, 2017 at 2:56am
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) ;
}
May 21, 2017 at 11:43am
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])


May 21, 2017 at 5:11pm
Oh. That makes sense. Thank you!
Topic archived. No new replies allowed.