Constructor Problem

Discussion in 'C++' started by moojo1337, Jan 2, 2012.

  1. moojo1337

    moojo1337 New Member

    Joined:
    Jan 2, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice