Parameter list, pseudo-database, approach not scalable!

I have a file called jobDatabase.h which I would like to be able to fill up with as many _jobs as I feel like (maybe hundreds), but some of my function calls require me to load-in each job. Is there some way to avoid this need, b/c the argument list would become absurdly long.

I've considered using matrices, but can you mix data-types within an array? I don't think so.

I could maybe have one function to pre-load a desired set from the database of _job into job1, job2, job3, job4, but I'd prefer they all be available in whatever function I need them.

Please help!

1
2
3
4
5
6
class _job
{
public:
	string name, title;
	int salary, creditYearsMin;
};


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
#ifndef JOBDATABASE_H
#define JOBDATABASE_H

_job job1;
job1.name = "Labor Ready";
job1.title = "LABORER";
job1.salary = 12500;
job1.creditYearsMin = 0;

_job job2;
job2.name = "Widget Factory";
job2.title = "ENGINEER";
job2.salary = 65000;
job2.creditYearsMin = 4;

_job job3;
job3.name = "Hospital";
job3.title = "NURSE";
job3.salary = 150000;
job3.creditYearsMin = 6;

_job job4;
job4.name = "Hospital";
job4.title = "DOCTOR";
job4.salary = 350000;
job4.creditYearsMin = 8;

#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int _tmain(int argc, _TCHAR* argv[])
{
	init();
	
#include "jobDatabase.h"

	_user you;
	initUser(you);

	life(you, job1, job2, job3, job4);
	
	dispUser(you);
	system("PAUSE");
	return 0;
}


void life (_user &you, _job job1, _job job2, _job job3, _job job4)

findJob(you, job1, job2, job3, job4);

etc.
Try with a deque of _job objects ( http://www.cplusplus.com/reference/stl/deque/ )
Last edited on
Okay, I've got them loaded into a deck. Now, how do I pass them as a function parameter?

Line: 17 void life (_user &you, deque dqJobList, _job job1, _job job2, _job job3, _job job4);

Line: 28 life(you, dqJob, job1, job2, job3, job4);

Line: 35 void life (_user &you, deque dqJobList, _job job1, _job job2, _job job3, _job job4)

(17): error C2955: 'std::deque' : use of class template requires template argument list

(28): error C2664: 'life' : cannot convert parameter 2 from 'std::deque<_Ty>' to 'std::deque'
with
[
_Ty=_job
]

(35): error C2955: 'std::deque' : use of class template requires template argument list
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\deque(970) : see declaration of 'std::deque'

You need to give deque the template argument: deque<_job>.
When you pass the deque you don't need to pass again all the objects as they are already contained in it
When you pass the deque you don't need to pass again all the objects as they are already contained in it

Yeah, I know, sorry, those were in for my own debugging/checking.

You need to give deque the template argument: deque<_job>.

I do:
deque<_job> dqJob(5);

My life function doesn't like when I call dqJob a _job or a deque, so what do I call it?

void life (_user &you, _job dqJob

line 28:
life(you, dqJob

(28): error C2664: 'life' : cannot convert parameter 2 from 'std::deque<_Ty>' to '_job'
with
[
_Ty=_job
]



Aha!

void life (_user &you, deque<_job> dqJob

lol
You should pass containers by reference, because they are expensive to copy:
void life (_user &you, const deque<_job> &dqJob);
Looks like you may want to use an actual database as opposed to a pseudo-db, expecially if you're going to have hundreds of job entries. This looks like a classic example for a relational database.
Thanks, Bazzy. I'll read up on const.

jRaskell, yeah, you're probably right, it may be time to branch out. Any suggestions on where to get started with a relational db?
Notice the '&' after the type, const TYPE & means 'a const reference of TYPE', which means that the argument doesn't get copied (reference) and that you can't modify it in the function (const)
Thanks for the explanation. I did in fact forget the '&'.
Topic archived. No new replies allowed.