Constructor Problem

moojo1337's Avatar, Join Date: Jan 2012
Newbie Member
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, Shift and ShiftBloc classes look like that

Code:
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;
	}
};
Code:
#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;
	}
};
Code:
#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
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Hmm, this is a problem, as clearly you have defined one:
Code:
	ShiftBloc::ShiftBloc(Time startTime) {
		this->startTime = startTime;
	}
What are the filenames of the above three code segments?

Where is your main function?

Did you post the code for ShiftBloc.h? If not, could you?