Constructor problem

Hi, I have just started learning C++ and I usually code in Java.

I created a class Shift which is compose of n amount of ShiftBloc (which is like a working shift split into ex 8 hours of shift) each ShiftBlocs are taking as argument an instance of the class Time. No matter what I do it keeps saying that there are no instance of such a constructor:

ShiftBloc::ShiftBloc(Time startTime) {...}

So I can't do (with an instance of Time) -> ShiftBloc s = ShiftBloc(startTime);
I can only instanciate Shift with it's default constructor Shift()
I tried creating a constructor with just an int as an argument and it works so it seems that it's only when I try to pass a class I created as an argument... The answer is probably very simple but I can't seem to find the problem and I've been looking for a while :(

my Time and Shift class looks like that

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class Time {
private:
	int hour;
	int minute;

public:
	Time() {

	}

	Time(int hour, int minute) {
	this->hour = hour;
	this->minute = minute;
	}

	int getHour() {
		return hour;
	}

	int getMinute() {
		return minute;
	}
};

#include "Time.h"
class ShiftBloc {
private:
	Time startTime;
	float cashAquired;

public:
	ShiftBloc::ShiftBloc() {}

	ShiftBloc::ShiftBloc(Time startTime) {
		this->startTime = startTime;
	}

	float ShiftBloc::getCashAquired() {
		return cashAquired;
	}

	Time ShiftBloc::getStartTime() {
		return startTime;
	}
};

#include "ShiftBloc.h"
#include "Time.h"
class Shift {
private:
	const int SHIFTLENGTH = 8;
	ShiftBloc shift[SHIFTLENGTH];
	Employee team[];

	
	void setShift(Time startTime) {
		ShiftBloc s(startTime);
		// I want to do more with the startTime
                // but for testing purpose I am just creating an instance
	}

public:
	Shift(Time startTime) {
		this->setShift(startTime);
	}
};


Thanks for your help :)

William
ShiftBloc::ShiftBloc() {}
Your functions are already in the class scope, you do not need to do that. Just do this:
ShiftBloc() {}
and the same for the rest. Where did you learn this from?
Many tutorial seems to include the scope anyway but I admit it's superfluous. As you can see I didn't do it on the other classes :p

But still, it doesn't solve my problem


*Edit: actualy, it was because I tryed to put the functions in a cpp instead to see if it could be where the problem lies :S ... I tryed alot of different possibilities without success. I just copy pasted them back into the header without removing the scope.
William
Last edited on
Topic archived. No new replies allowed.